Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top