Open AL 的函数在 ubuntu 中使用 g++ 编译时给出未定义引用的错误

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

本文关键字:编译 未定义 错误 引用 g++ 函数 AL ubuntu Open      更新时间:2023-10-16

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

sudo apt-get install libopenal-dev

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

sudo apt-get install libalut0 libalut-dev

我也从 http://kcat.strangesoft.net/openal.html 中分叉开了艾尔并安装了它。但是当我尝试编译这个简单的程序时:

#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;
}

我收到此错误:

/

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

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

我编译了它

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

他们都给出了同样的错误。

你需要链接到 OpenAl 库:

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