即使链接了库,也未定义对符号的引用 [英] Undefined reference to symbol, even though the library is linked
问题描述
链接正在处理的项目时,链接器会出现以下错误:
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
问题是,libsndfile.so已经在libsfml21rca.a之前链接了,所以我不知道问题出在哪里.
The thing is, libsndfile.so is already linked before libsfml21rca.a, so I have no idea where the problem is.
我正在使用Code :: Blocks 10.05
I'm using Code::Blocks 10.05
谢谢您的帮助
这是链接命令:
g ++ -L包含和库/lib" -L包含和库/lib/raknet3_731" -L包含和库/lib/d3d_new/x86" -L包含和库/lib/ogg" -L 包含和库文件/lib/sdl" -LBullet/lib -o(文件名)...(大量目标文件)-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
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
推荐答案
链接器仅对库文件运行一遍.因此,如果库A中有某些内容需要库B中的某些内容,则需要具有g++ objects... -llibA -llibB
,如果使用g++ objects... -llibB -llibA
,它将以您显示的方式失败.
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.
因此,在您的情况下,请将-lsndfile
放在"../Includes and Libs/lib/libsfml21rca.a"
之后.
So, in your case, put the -lsndfile
after "../Includes and Libs/lib/libsfml21rca.a"
.
(其想法是在"Includes and Libs"目录中放置空格-不是我见过的最好的主意...)
(And whose idea was it to put spaces in a the "Includes and Libs" directory - not the best idea I've seen...)
这篇关于即使链接了库,也未定义对符号的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!