11

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

matuzalem
  • 357
  • 1
  • 2
  • 14

1 Answers1

9

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

Mats Petersson
  • 123,518
  • 13
  • 127
  • 216
  • 1
    I'll give it a shot. In my defence, I jumped on this project few days ago, so all the terrible names (there is more of it) were not made by me. **EDIT:** Blast damnation, it worked! Thank you, Mats Peterson. – matuzalem Jul 19 '13 at 09:01
  • @Mats frankly, I find the single pass over library more off-putting. There have been countless SO questions like the OP's all because of `ld` linker's limition. Microsoft's `LINK` tool doesn't have this problem for instance. Neither does Embarcadero's ilinker. – greatwolf Jul 19 '13 at 09:05
  • @greatwolf Unfortunately, my job is to make the project run on Unix platforms. So much for Microsoft's `LINK`. – matuzalem Jul 19 '13 at 09:08
  • It is open source, I'm sure a patch would be welcome... Although I suspect that would break things somewhere - or at least if it was really easy to fix without drawback, someone would have fixed it. – Mats Petersson Jul 19 '13 at 09:09