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

…衆ロ難τιáo~ 提交于 2020-08-20 06:34:27

问题


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

sudo apt-get install libopenal-dev

And also I installed alut installed with this command

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:

#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'

collect2: error: ld returned 1 exit status

I compiled it with

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

Both of them gave same error.


回答1:


You need to link to the OpenAl library:

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


来源:https://stackoverflow.com/questions/44694002/functions-of-open-al-giving-error-of-undefined-reference-while-compiling-with-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!