在使用ubuntu中的g ++进行编译时,Open AL的函数给出了未定义引用的错误[复制]

时间:2022-07-20 23:40:17

This question already has an answer here:

这个问题在这里已有答案:

I am completely new to Open AL. So I started with installing Open AL library through command line

我是Open AL的新手。所以我开始通过命令行安装Open AL库

sudo apt-get install libopenal-dev

And also I installed alut installed with this command

我还安装了使用此命令安装的alut

sudo apt-get install libalut0 libalut-dev

Also I forked open Al from http://kcat.strangesoft.net/openal.html and installed it also. But when I am trying to compile this simple program:

我还从http://kcat.strangesoft.net/openal.html分叉打开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;
}

I am getting this error:

我收到此错误:

/tmp/cchMpaeS.o: In function main': altest.cpp:(.text+0xe): undefined reference toalcOpenDevice'

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

collect2: error: ld returned 1 exit status

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

I compiled it with

我编译了它

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

Both of them gave same error.

他们俩都犯了同样的错误。

1 个解决方案

#1


0  

You need to link to the OpenAl library:

您需要链接到OpenAl库:

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

#1


0  

You need to link to the OpenAl library:

您需要链接到OpenAl库:

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