10
votes

When linking a project I am working on, the linker gives the following errors:

/usr/bin/ld: ../Includes and Libs/lib/libsfml21rca.a(SoundFile.o): undefined reference to symbol 'sf_read_short@@libsndfile.so.1.0'

/usr/bin/ld: note: 'sf_read_short@@libsndfile.so.1.0' is defined in DSO /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libsndfile.so so try adding it to the linker command line

/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libsndfile.so: could not read symbols: Invalid operation

The thing is, libsndfile.so is already linked before libsfml21rca.a, so I have no idea where the problem is.

I'm using Code::Blocks 10.05

Thanks for help in advance

EDIT:

Here is the linking command:

g++ -L"Includes and Libs/lib" -L"Includes and Libs/lib/raknet3_731" -L"Includes and Libs/lib/d3d_new/x86" -L"Includes and Libs/lib/ogg" -L"Includes and Libs/lib/sdl" -LBullet/lib -o (filename) ...(a whole lot of object files) -lGLEW -lglfw -lGL -lGLU -lpthread -lopenal -ljpeg -lfreetype -lsndfile -lXrandr -lsfml-system -lsfml-window -lsfml-audio ../Bullet/lib/LinearMath.lib ../Bullet/lib/BulletCollision.lib ../Bullet/lib/BulletDynamics.lib "../Includes and Libs/lib/raknet3_731/RakNetLibStaticDebug.lib" "../Includes and Libs/lib/libsfml21rca.a" ../../../../../../home/msabol/Desktop/SFML/sfml2st/sfmlVideo/sfmlVideo/bin/Release/libsfmlVideo.a ../../../../../../home/msabol/Desktop/SFML/sfmlVideo/bin/Release/libsfmlVideo.a

1
Try changing the order of linking? - PP.
How exactly am I supposed to change it? Everything is linked in correct order, or at least it seems so. - matuzalem
Add the command C::B is using to link to your question. (do not add it as a comment!) - greatwolf
possible duplicate of library is linked but reference is undefined - user529758
@H2CO3 I'll keep that in mind. - matuzalem

1 Answers

8
votes

The linker only runs one pass over the library files. So if you have something in Library A that needs something in Library B, you need to have g++ objects... -llibA -llibB, if you use g++ objects... -llibB -llibA it will fail in the manner you show.

So, in your case, put the -lsndfile after "../Includes and Libs/lib/libsfml21rca.a".

(And whose idea was it to put spaces in a the "Includes and Libs" directory - not the best idea I've seen...)