目前,我正试图用FMOD音频库编写一个小程序,但很难理解如何链接它们。
我有一个小程序,如下所示
#include "/home/me/fmod_test/api/lowlevel/inc/fmod.h"
#include "/home/me/fmod_test/api/lowlevel/inc/fmod.hpp"
#include "/home/me/fmod_test/api/lowlevel/inc/fmod_errors.h"
#include <iostream>
using namespace std;
int main()
{
FMOD::System *system;
FMOD::Sound *sound1;
FMOD::System_Create(&system); // create an instance of the game engine
}但是当我尝试使用
g++ -L/home/me/fmod_test/api/lowlevel/lib/x86_64 -lfmod -lfmodL test.cpp -o test我遇到了这样的错误
In function `FMOD::System_Create(FMOD::System**)':
test.cpp:(.text._ZN4FMOD13System_CreateEPPNS_6SystemE[_ZN4FMOD13System_CreateEPPNS_6SystemE]+0x14): undefined reference to `FMOD_System_Create'我包括了屏幕截图,以表明这些库和标题确实存在于我的系统中。


有趣的是,如果我注释掉System_Create调用FMOD::System和声音初始化仍然很好。
我的链接是否不正确,我不明白为什么这不起作用(是的,我使用的是x86_64体系结构,根据-a的输出)
发布于 2015-05-31 16:07:16
g++ -L/home/me/fmod_test/api/lowlevel/lib/x86_64 -lfmod -lfmodL test.cpp -o test
此命令行是向后的。正如在this answer中所解释的,库必须遵循命令行中的源和对象文件(答案说,对于共享库来说,顺序并不重要,但这部分答案是错误的(至少对于某些链接程序))。尝试:
g++ -L/home/me/fmod_test/api/lowlevel/lib/x86_64 test.cpp -o test -lfmod -lfmodL https://stackoverflow.com/questions/30554055
复制相似问题