SFML community forums

Help => Audio => Topic started by: SkeleDotCpp on December 28, 2017, 09:44:29 pm

Title: "Undefined reference to" error when I build my game.
Post by: SkeleDotCpp on December 28, 2017, 09:44:29 pm
When I run my game, I get these errors:
Quote
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp|| undefined reference to `sf::FileInputStream::FileInputStream()'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp|| undefined reference to `sf::FileInputStream::open(std::string const&)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp|| undefined reference to `sf::MemoryInputStream::MemoryInputStream()'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(InputSoundFile.cpp.obj):InputSoundFile.cpp|| undefined reference to `sf::MemoryInputStream::open(void const*, unsigned int)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::MemoryInputStream::MemoryInputStream()'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::MemoryInputStream::open(void const*, unsigned int)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::MemoryInputStream::seek(long long)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::FileInputStream::FileInputStream()'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::FileInputStream::open(std::string const&)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::FileInputStream::seek(long long)'|
s Folder\CodeBlocks\SFML-2.4.2\lib\libsfml-audio-s.a(SoundFileFactory.cpp.obj):SoundFileFactory.cpp|| undefined reference to `sf::FileInputStream::~FileInputStream()'|

This is the code that causes this:
sf::SoundBuffer rifleShotBuffer;
if (!rifleShotBuffer.loadFromFile("Audio/RifleShot.wav")) {
   return EXIT_FAILURE;
}
 

Can someone explain why this happens?
Title: Re: "Undefined reference to" error when I build my game.
Post by: eXpl0it3r on December 29, 2017, 10:10:34 am
Sounds like you didn't link the libraries in the right order. It should always be X depends on Y, the X needs to be specified before Y.
sfml-audio depends on sfml-system...
Title: Re: "Undefined reference to" error when I build my game.
Post by: SkeleDotCpp on January 01, 2018, 07:43:54 pm
This is how I linked my libraries:
Quote
sfml-graphics-s
(All dependencies for graphics)
sfml-window-s
(All dependencies for window)
sfml-system-s
(All dependencies for system)
sfml-audio-s
(All dependencies for audio)

Is this the right order?
Title: Re: "Undefined reference to" error when I build my game.
Post by: eXpl0it3r on January 01, 2018, 08:45:10 pm
No, read again or read the official tutorial

Sounds like you didn't link the libraries in the right order. It should always be X depends on Y, the X needs to be specified before Y.
sfml-audio depends on sfml-system...
Title: Re: "Undefined reference to" error when I build my game.
Post by: SkeleDotCpp on January 03, 2018, 09:12:22 pm
I have re checked and fixed the issue with the order. Thank you :)