2

I am currently trying to write a small program using FMOD audio libraries but am having trouble understanding how to link them.

I have a small program that looks as follows

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

But when I attempt to compile using

g++ -L/home/me/fmod_test/api/lowlevel/lib/x86_64 -lfmod -lfmodL test.cpp -o test

I get an error like this

In function `FMOD::System_Create(FMOD::System**)':
test.cpp:(.text._ZN4FMOD13System_CreateEPPNS_6SystemE[_ZN4FMOD13System_CreateEPPNS_6SystemE]+0x14): undefined reference to `FMOD_System_Create'

I have included screenshots to show that these libraries and headers do actually exist in my systementer image description here enter image description here

Interestingly enough, if I comment out the System_Create call the FMOD::System and Sound initializations still work fine.

Am I linking incorrectly, I cant figure out why this wouldnt be working (and yes I am on x86_64 architecture as per the output of uname -a)

suphug22
  • 181
  • 1
  • 8
  • I think you are missing libfmodex.so – JosEduSol May 31 '15 at 05:42
  • there does not appear to be a libfmodex.so library anywhere in the latest versions of FMOD, older versions do appear to have this library and I tried to compile an older version using `g++ -I/home/me/fmod_test/fmodex/inc/ -L/home/me/fmod_test/fmodex/lib/ -lfmodex64 -lfmodexL64 test.cpp -o test` but still had the same error – suphug22 May 31 '15 at 05:50

1 Answers1

1

g++ -L/home/me/fmod_test/api/lowlevel/lib/x86_64 -lfmod -lfmodL test.cpp -o test

This command line is backwards. As explained in this answer, libraries must follow sources and object files on command line (the answer says that the order doesn't matter for shared libraries, but that part of the answer is wrong (for at least some linkers)). Try:

g++ -L/home/me/fmod_test/api/lowlevel/lib/x86_64 test.cpp -o test -lfmod -lfmodL 
Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362