C ++:未定义的'FMOD :: X'引用

时间:2011-03-14 19:48:22

标签: c++ codeblocks undefined-reference fmod

在浏览各种声音API库之后,我决定暂时使用FMOD。

问题是每当我尝试编译其中一个代码示例时,我都会遇到以下错误:

obj\Release\main.o:main.cpp|| undefined reference to `FMOD::System::getVersion(unsigned int*)@8'|

obj\Release\main.o:main.cpp|| undefined reference to `FMOD::System::init(int, unsigned int, void*)@16'|

obj\Release\main.o:main.cpp|| undefined reference to `FMOD::System::createSound(char const*, unsigned int, FMOD_CREATESOUNDEXINFO*, FMOD::Sound**)@20'|

obj\Release\main.o:main.cpp|| undefined reference to `FMOD::Sound::setMode(unsigned int)@8'|

我正在使用的代码示例是:

#include <D:\Games\FMOD Programmers API Win32\api\inc\fmod.hpp>
#include <D:\Games\FMOD Programmers API Win32\api\inc\fmod_errors.h>
#include <sstream>
#include <windows.h> // for PlaySound()
#include <time.h>
#include <mmsystem.h>    
using namespace std;
int main(int argc, char* argv[])
{
FMOD::System     *system;
FMOD::Sound      *sound1, *sound2, *sound3;
FMOD::Channel    *channel = 0;
FMOD_RESULT       result;
int               key;
unsigned int      version;

/*
    Create a System object and initialize.
*/
result = FMOD::System_Create(&system);


result = system->getVersion(&version);

result = system->init(32, FMOD_INIT_NORMAL, 0);


result = system->createSound("../media/drumloop.wav", FMOD_HARDWARE, 0, &sound1);


result = sound1->setMode(FMOD_LOOP_OFF);    /* drumloop.wav has embedded loop points   which automatically makes looping turn on, */
                                            /* so turn it off here.  We could have also just put FMOD_LOOP_OFF in the above CreateSound call. */

 // Code continues into other bits that work...

我正在使用最新版本的FMOD,并使用Code :: Blocks IDE(版本10.05)和GNU GCC编译器。该项目的类型为“控制台应用程序”。 fmodex.dll文件位于我的项目的文件夹中。我使用的是Windows XP 32位SP3。

我已链接到libfmodex.a库并尝试链接到其中的其他库,但这并不能解决问题。

因此,我的问题是,我需要做些什么来阻止这些错误的发生?就像我在使用其他库之前遇到类似的“Undefined reference to x”错误一样。我忘记了在Code :: Blocks中链接到它们,并且一旦我这样做,它们就会工作。

如果您需要有关代码等的更多信息,请说明。

3 个答案:

答案 0 :(得分:4)

将FMOD与Code :: Blocks一起使用时,您需要使用C API,而不是C ++ API。 FMOD是使用Visual Studio构建的,因此C ++符号使用VC修改方案。 “FMOD for Windows入门”文档中有一个注释提到了这一点。

http://en.wikipedia.org/wiki/Name_mangling#How_different_compilers_mangle_the_same_functions

答案 1 :(得分:1)

有一个Windows框准备好验证这个,但尝试用包含路径中的正斜杠替换这些反斜杠,或者转义反斜杠。

#include <D:/Games/FMOD Programmers API Win32/api/inc/fmod.hpp>
#include <D:/Games/FMOD Programmers API Win32/api/inc/fmod_errors.h>

#include <D:\\Games\\FMOD Programmers API Win32\\api\\inc\\fmod.hpp>
#include <D:\\Games\\FMOD Programmers API Win32\\api\\inc\\fmod_errors.h>

(或者,更好的是,只需将D:\Games\FMOD Programmers API Win32\api\inc\添加到包含路径列表中,并按文件名而不是完整路径包含文件;然后您的代码可能实际编译到您的特定计算机以外的某处!)

答案 2 :(得分:0)

那些未定义的引用错误意味着编译器,或者说编译器的链接器部分无法找到库。

我不使用Code :: Blocks,所以我不知道设置在哪里,但你需要告诉你的项目使用库以及在哪里找到它。

将DLL放在目录中就足以运行程序,但是为了链接它,你需要一个.lib文件。