Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile OpenAL program with g++ (Ubuntu)?

I am trying to find a way of getting OpenAL to work on my computer:

Ubuntu 12.10 (running on 2010 intel i7 Macbook Pro)

I installed the OpenAL library from the terminal:

$ sudo apt-get install libopenal-dev

Everything went well. Now I tried to create a simple C++ program where I include the library:

#include <iostream>
#include <AL/alut.h>

using namespace std;

int main(){
    cout << "Hello, world" << endl;
}

No matter how hard I tried, the closest I came to finding how to compile it with g++ was:

$ g++ test.cpp -lalut 

This gives the following error:

test.cpp:2:21: fatal error: AL/alut.h: No such file or directory
compilation terminated.

Any ideas on how to get OpenAL linked to my projects? I spent hours on Google and the answer doesn't seem to exist. I probably did something fundamentally wrong, since I'm fairy new to Linux c++ development. Thanks.

Edit: changed for reference:

$ g++ -lalut test.cpp

to

$ g++ test.cpp -lalut

(the later is the correct way of doing it, I posted it wrong).

like image 799
Sefu Avatar asked Dec 08 '22 17:12

Sefu


2 Answers

Make sure you have alut installed

sudo apt-get install libalut-dev
like image 144
Jacob Parker Avatar answered Dec 11 '22 06:12

Jacob Parker


Your error message indicates that your compiler isn't able to find the header file for ALUT (a utility toolkit to make getting started with OpenAL development easier). This may be for one of two reasons:

  1. You haven't installed the library at all. In that case, use apt-get install as you did with OpenAL itself.

  2. The header is present somewhere on your system, but not in the default include path. If you are able to locate the library on the file system, make sure to make its include directory known to g++ using the -I switch.

Generally, when linking to a library using g++ (or MinGW for what it matters), three things need to be available to the compiler toolchain during compilation:

  • The library's include directory (where the header files are) - using -I
  • The directory of the library files - using -L
  • The name of the library file(s) - using -l

Normally on Linux, the first two are kind of automatically handled during the installation procedure of the appropriate library package. Nevertheless, if your library is resting someplace else than the standard directories, you have to explicitly specify include and library path.

For a concise introduction to the usage of g++, see also here.

Edit: I realize I spent a little too much time fiddling with my answer, while your problem was already solved. But I hope the information above is useful to you anyway!

like image 33
Zultar Avatar answered Dec 11 '22 07:12

Zultar