在 ubuntu 中使用 g++ 编译时,Open AL 的函数给出未定义引用的错误

Functions of Open AL giving error of undefined reference while compiling with g++ in ubuntu

我对 Open AL 完全陌生。 所以我开始通过命令行安装 Open AL 库

sudo apt-get install libopenal-dev

而且我还用这个命令安装了 alut

sudo apt-get install libalut0 libalut-dev

我还从 http://kcat.strangesoft.net/openal.html fork open Al 并安装了它。 但是当我试图编译这个简单的程序时:

#include <stdio.h>
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alut.h>
int main(){
   ALCdevice *device;
   device=alcOpenDevice(NULL);
   if(!device)
   {
       printf("no device found");
   }
   else
   {
       printf("device found");
   }
   return 0;
}

我收到这个错误:

/tmp/cchMpaeS.o: 在函数中 main': altest.cpp:(.text+0xe): undefined reference toalcOpenDevice'

collect2:错误:ld 返回了 1 个退出状态

我用

编译的
g++ altest.cpp
g++ -std=c++11 altest.cpp

他们都给出了同样的错误。

您需要link到OpenAl库:

g++ -std=c++11 altest.cpp -lopenal