问题描述
链接正在处理的项目时,链接器会出现以下错误:
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
谢谢您的帮助
这是链接命令:
推荐答案
链接器仅对库文件运行一遍.因此,如果库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...)
这篇关于即使链接了库,也未定义对符号的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!