C++:对“FMOD::X”的未定义引用

发布于 2024-10-21 15:27:19 字数 2072 浏览 8 评论 0原文

在查阅了各种声音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 中链接到它们,一旦我这样做,它们就会起作用。

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

After looking around for various sound API libraries, I have decided to use FMOD for the time being.

Problem is that whenever I try to compile one of the code examples, I get the following errors:

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'|

The code example that I am using being this:

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

I am using the latest version of FMOD and am using the Code::Blocks IDE (ver 10.05), with the GNU GCC compiler. The project is of type "Console application". The fmodex.dll file is in the folder of my project. I am using windows XP 32 bit SP3.

I have linked to the libfmodex.a library and have tried linking to the other libraries it has there as well, but this does not solve the problem.

My question is, therefore, what do I need to do to stop these errors occurring? As when I encountered similar "Undefined reference to x" errors before using other libraries. I had just forgotten to link to them in Code::Blocks and as soon as I did, they would work.

Do say if you need more information regarding the code etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

提赋 2024-10-28 15:27:19

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

When using FMOD with Code::Blocks you need to use the C API, not the C++ API. FMOD is built with Visual Studio, therefore the C++ symbols use the VC mangling scheme. There is a note in the "Getting Started with FMOD for Windows" document that mentions this.

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

追风人 2024-10-28 15:27:19

我没有准备好 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\ 添加到包含路径列表中,并按文件名而不是完整路径包含文件;然后你的代码实际上可能会在您的特定计算机之外的其他地方进行编译!)

I do not have a Windows box ready to verify this on, but try replacing those backslashes with forward slashes in the include paths, or escape the backslashes.

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

or

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

(Or, better, just add D:\Games\FMOD Programmers API Win32\api\inc\ to your list of include paths, and include the files by filename instead of full path; then your code might actually compile somewhere other than your specific computer!)

辞旧 2024-10-28 15:27:19

这些未定义的引用错误意味着编译器,或者更确切地说是编译器的链接器部分,无法找到该库。

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

只需将 DLL 放入目录中就足以运行程序,但要链接它,您需要一个 .lib 文件。

Those undefined reference errors mean that the compiler, or rather the linker part of the compiler, cannot find the library.

I don't use Code::Blocks so I don't know where the setting is, but you need to tell your project to use the library and where to find it.

Just putting the DLL in the directory is enough for running the program, but for linking it you need a .lib file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文