Search code examples
c++linuxubuntu-16.04openalopenal-soft

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


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.


Solution

  • You need to link to the OpenAl library:

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