如何使用 mingw64 link SFML 音频项目

How to link SFML-audio project with mingw64

当我尝试在 C++ 中使用 mingw64 编译 SFML 音频项目时收到错误消息。我做了很多研究,但我不知道如何解决这个错误。这是我在 makefile 中使用的编译命令:

g++ -g -std=c++17 src/*.cpp -o Firefighter -DSFML_STATIC -I include -L lib -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lsfml-audio-s -lopenal32 -lFLAC -lvorbisenc -lvorbisfile -lvorbis -logg -lopengl32 -lwinmm -lgdi32 -lfreetype

我认为这是一个错误:

c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp:(.text+0x100): undefined reference to `sf::FileInputStream::FileInputStream()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp:(.text+0x113): undefined reference to `sf::FileInputStream::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp:(.text+0x273): undefined reference to `sf::MemoryInputStream::MemoryInputStream()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp:(.text+0x289): undefined reference to `sf::MemoryInputStream::open(void const*, unsigned long long)'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x4b): undefined reference to `sf::Thread::wait()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x14c): undefined reference to `sf::Thread::wait()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x172): undefined reference to `sf::Thread::launch()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x327): undefined reference to `sf::Thread::~Thread()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x36c): undefined reference to `sf::Thread::wait()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x37c): undefined reference to `sf::Thread::~Thread()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x3dc): undefined reference to `sf::Thread::wait()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0x3ec): undefined reference to `sf::Thread::~Thread()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xf5e): undefined reference to `sf::Thread::wait()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundStream.cpp.obj):SoundStream.cpp:(.text+0xfcf): undefined reference to `sf::Thread::launch()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x533): undefined reference to `sf::MemoryInputStream::MemoryInputStream()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x541): undefined reference to `sf::MemoryInputStream::open(void const*, unsigned long long)'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x573): undefined reference to `sf::MemoryInputStream::seek(long long)'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x840): undefined reference to `sf::FileInputStream::FileInputStream()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x84b): undefined reference to `sf::FileInputStream::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x883): undefined reference to `sf::FileInputStream::seek(long long)'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x89a): undefined reference to `sf::FileInputStream::~FileInputStream()'
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: lib/libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp:(.text+0x9d8): undefined reference to `sf::FileInputStream::~FileInputStream()'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:5: debug-window] Error 1

您需要 link sfml-audio-s sfml-system-s 之前,依赖项的 linking 顺序对于 GCC 很重要。

您可以在官方教程中找到每个 link 的正确顺序,有一个 table 包含所有这些:https://www.sfml-dev.org/tutorials/2.5/start-cb.php