【问题标题】:SFML 2.3 and CodeBlocks error compilationSFML 2.3 和 CodeBlocks 错误编译
【发布时间】:2026-02-22 13:30:01
【问题描述】:

我正在尝试使 sfml 与代码块一起使用。我做了这个视频教程中所说的一切:https://www.youtube.com/watch?v=gEGWO8ug2bY

如果我只添加 SFML/Graphics.hpp,一切正常,所以我的配置还不错。
但是如果我尝试添加 SFML/Audio.hpp(我需要在我的项目中添加声音)并编写“sf::Music background_music;”我得到错误:

    ||=== Build: Debug in JeudeGo (compiler: GNU GCC Compiler) ===|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundStream.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundStream.cpp|52|undefined reference to `sf::Thread::~Thread()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundStream.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundStream.cpp|70|undefined reference to `sf::Thread::wait()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundStream.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundStream.cpp|59|undefined reference to `sf::Thread::~Thread()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundStream.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundStream.cpp|59|undefined reference to `sf::Thread::~Thread()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundStream.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundStream.cpp|135|undefined reference to `sf::Thread::launch()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundStream.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundStream.cpp|166|undefined reference to `sf::Thread::wait()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundStream.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundStream.cpp|228|undefined reference to `sf::Thread::launch()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(InputSoundFile.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\InputSoundFile.cpp|74|undefined reference to `sf::FileInputStream::FileInputStream()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(InputSoundFile.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\InputSoundFile.cpp|79|undefined reference to `sf::FileInputStream::open(std::string const&)'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(InputSoundFile.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\InputSoundFile.cpp|117|undefined reference to `sf::MemoryInputStream::MemoryInputStream()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(InputSoundFile.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\InputSoundFile.cpp|122|undefined reference to `sf::MemoryInputStream::open(void const*, unsigned int)'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundFileFactory.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundFileFactory.cpp|71|undefined reference to `sf::FileInputStream::FileInputStream()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundFileFactory.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundFileFactory.cpp|72|undefined reference to `sf::FileInputStream::open(std::string const&)'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundFileFactory.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundFileFactory.cpp|78|undefined reference to `sf::FileInputStream::seek(long long)'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundFileFactory.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundFileFactory.cpp|84|undefined reference to `sf::FileInputStream::~FileInputStream()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundFileFactory.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundFileFactory.cpp|84|undefined reference to `sf::FileInputStream::~FileInputStream()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundFileFactory.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundFileFactory.cpp|95|undefined reference to `sf::MemoryInputStream::MemoryInputStream()'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundFileFactory.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundFileFactory.cpp|96|undefined reference to `sf::MemoryInputStream::open(void const*, unsigned int)'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundFileFactory.cpp.obj):D:\sfml-release\_Sources\SFML\src\SFML\Audio\SoundFileFactory.cpp|101|undefined reference to `sf::MemoryInputStream::seek(long long)'|
D:\Info\SFML-2.3\lib\libsfml-audio-s-d.a(SoundFileFactory.cpp.obj):D:\sfml-release\_Sources\SFML\include\SFML\System\MemoryInputStream.hpp|43|undefined reference to `vtable for sf::MemoryInputStream'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_write'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| more undefined references to `oggpack_write' follow|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_readinit'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_readinit'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| more undefined references to `oggpack_read' follow|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_read'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| more undefined references to `oggpack_read' follow|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_writeinit'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_bytes'|
D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to `oggpack_writeclear'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

我的链接库(按此顺序):

sfml-graphics-s-d 
sfml-window-s-d 
sfml-system-s-d 
sfml-audio-s-d 
sfml-network-s-d 
flac 
ogg 
vorbis 
vorbisenc 
vorbisfile 
openal32
jpeg
freetype
ws2_32
gdi32
opengl32
winmm 

还有#defines:

SFML_STATIC
UNICODE

感谢您的帮助!

【问题讨论】:

    标签: c++ compilation codeblocks sfml


    【解决方案1】:

    尝试重新排序您的链接。 Sfml 系统应该在您的链接器设置中最后或第一个。它应该是 SFML 链接的最后一个。

    【讨论】:

    • 好的,我重新排序了我的链接。好像比以前好多了!现在,如果 Sfml 系统在我的链接器设置中位于最后,我会收到错误:D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to oggpack_write| D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| more undefined references to oggpack_write follow| D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to oggpack_readinit| D:\Info\SFML-2.3\lib\libvorbis.a(info.o):info.c|| undefined reference to oggpack_read|
    • @Nicole1717 你记得在你的可执行路径中包含 dll。 Libsndfile和openal应该在sfml下载的bin目录下