打开AL的函数在使用Ubuntu中的g ++进行编译时给出未定义引用的错误

问题描述:

我对Open AL完全陌生。 于是我开始通过命令行打开AL的函数在使用Ubuntu中的g ++进行编译时给出未定义引用的错误

sudo apt-get install libopenal-dev 

安装Open AL库,我也安装了这个命令

sudo apt-get install libalut0 libalut-dev 

而且我分叉开放铝从http://kcat.strangesoft.net/openal.html 安装ALUT并安装它也。 但是,当我试图编译这个简单程序:

#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 to alcOpenDevice”

collect2:错误:LD返回1退出状态

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

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

+0

如果你尝试过的东西,你有问题吧,请发表你尝试过什么。在这种情况下,你试图编译你的程序,但是你还没有发布你尝试使用的命令。所以发布该命令。 – nos

+0

@nos我编辑了问题 – Souravirus

您需要链接到的OpenAL库:

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

感谢它的工作 – Souravirus