gpt4 book ai didi

c++ - 对符号的 undefined reference ,即使库已链接

转载 作者:可可西里 更新时间:2023-11-01 16:07:29 27 4
gpt4 key购买 nike

链接我正在处理的项目时,链接器出现以下错误:

/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 之前,所以我不知道问题出在哪里。

我正在使用 Code::Blocks 10.05

提前感谢您的帮助

编辑:

链接命令如下:

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 它将以您显示的方式失败。

因此,在您的情况下,将 -lsndfile 放在 "../Includes and Libs/lib/libsfml21rca.a" 之后。

(谁的想法是在“Includes and Libs”目录中放置空格 - 这不是我见过的最好的想法......)

关于c++ - 对符号的 undefined reference ,即使库已链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17741613/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com