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

∥☆過路亽.° 提交于 2019-12-06 05:20:52

问题


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).


回答1:


Make sure you have alut installed

sudo apt-get install libalut-dev



回答2:


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!




回答3:


Gracias busque esta info por todos lados.

En resumen:

sudo apt-get install libasound-dev sudo apt-get install libopenal-dev sudo apt-get install libalut-dev

recuerden incluir la libreria openAL en

Project -> Properties -> C/C++ Build -> Settings -> Compiler -> Includes



来源:https://stackoverflow.com/questions/15452676/how-to-compile-openal-program-with-g-ubuntu

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