'How to link SFML-audio project with mingw64
I get an error message when I try to compile an SFML-audio project with mingw64 in C++. I've done a lot of research but I can't figure out how to fix this error. Here is the compile command I use in my 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
I get this as an error:
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
Solution 1:[1]
You need to link sfml-audio-s before sfml-system-s, the linking order of dependencies is important with GCC.
You can find the right order for each link on the official tutorial, there is a table with all of them : https://www.sfml-dev.org/tutorials/2.5/start-cb.php
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | swordfatih |