2

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.

James
  • 95
  • 1
  • 2
  • 6
  • I still require more assistance if possible. – James Mar 14 '11 at 20:29
  • how do you invoke the linker, eg line from makefile. – fizzer Mar 14 '11 at 20:49
  • I don't use a makefile (maybe i should, would need help with that though) i use project-build options.. linker settings and add the libary directory via that. (this is with codeblocks) – James Mar 14 '11 at 20:56
  • Sorry - I don't know it. Best of luck. – fizzer Mar 14 '11 at 20:58
  • @fizzer,Ah shame, thanks for trying to help though. Appreciated. – James Mar 14 '11 at 20:59
  • By the way, you should never use full paths for include files (set a include search path instead) and you should always use forward slashes, not backslashes. The compilers will convert them for you to whichever OS you use. – Zan Lynx Mar 14 '11 at 21:19
  • @Zan Lynx I know I should not use full paths for include but I am not quite sure how to set an include search path, also yes I will use foward slashes, thanks for that. – James Mar 14 '11 at 21:25
  • I have also now found a better solution, looking good: [link](http://www.ambiera.com/irrklang/index.html) – James Mar 15 '11 at 13:35

3 Answers3

4

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

Mathew Block
  • 1,613
  • 1
  • 10
  • 9
1

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

Nicholas Knight
  • 15,774
  • 5
  • 45
  • 57
  • I will try both of those things, although i may have already tried them... here i go... – James Mar 14 '11 at 20:13
  • Unfortunately neither of those things worked :( thanks for trying though. – James Mar 14 '11 at 20:16
  • oops forgot to at the comments at you so they would show up, sorry about that. – James Mar 14 '11 at 20:20
  • Of course, unfortunately unless the file name is the full one, the compiler will say the files do not exist, nether the less i will try this – James Mar 14 '11 at 20:42
  • As i expected, it does not reconise that this is a valid file path:C:\Documents and Settings\James Moran.HOME-B288D626D8\My Documents\C++ projects\Test Project\main.cpp|9|error: D:\Games\FMOD Programmers API Win32\api\inc: No such file or directory| – James Mar 14 '11 at 20:44
0

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.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131
  • Indeed, this is what I thought but as I said in my question I tried linking to them in codeblocks, yet it would still not solve all the errors. (curiously, it would solve one of them but not the other 4) – James Mar 14 '11 at 20:18
  • @Zan Lynx, I forgot to at the comments at you as well so you would see them, sorry about that, not sure the way i did it in this comment did such. – James Mar 14 '11 at 20:21
  • @James: Replying to an answer always notifies the answer author so that's ok. – Zan Lynx Mar 14 '11 at 21:17
  • @James: I see in your question that you linked a .a file. I don't know if that works in Windows. Doesn't it need to be a .lib file? – Zan Lynx Mar 14 '11 at 21:18
  • Heh, it just noticed that in the hint when writing a comment. Is there any other advice you could give me? – James Mar 14 '11 at 21:19
  • I'm not sure, it said in the readme file called "Which libary do i use?" to use the one that i linked, i even linked the fmodex_lcc.lib as well. Also, yes i forgot to put i was using windows (XP), i will put that in the answer too. – James Mar 14 '11 at 21:21
  • Also, for another part of the program i had to link to a .a file and that link worked just fine. – James Mar 14 '11 at 21:33