Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Elements of the SFML/Audio header files cause the linker to crash  (Read 2528 times)

0 Members and 1 Guest are viewing this topic.

ArchBTW

  • Newbie
  • *
  • Posts: 2
    • View Profile
Just started playing around with SFML today. When I downloaded it and used the code from the SFML and Linux tutorial everything worked fine, but when I tried to use the Audio headers it caused the linker to crash with errors about undefined references to everything from the Audio header files like sf::Music and such.
I have the header & lib files in the right place and the right compile commands. I am not sure whats wrong.

I use arch linux, g++ and vs code(I compile in the terminal not in vs code)

the code that causes ld to crash
// Load a music to play
sf::Music music;
if (!music.openFromFile("music.ogg"))
        return EXIT_FAILURE;
// Play the music
music.play();

the errors
/usr/bin/ld: main.o: in function `main':
main.cpp:(.text+0x1f3): undefined reference to `sf::Music::Music()'
/usr/bin/ld: main.cpp:(.text+0x23b): undefined reference to `sf::Music::openFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: main.cpp:(.text+0x278): undefined reference to `sf::SoundStream::play()'
/usr/bin/ld: main.cpp:(.text+0x28c): undefined reference to `sf::Music::~Music()'
/usr/bin/ld: main.cpp:(.text+0x32f): undefined reference to `sf::Music::~Music()'
collect2: error: ld returned 1 exit status

compilation commands
g++ -c main.cpp -I /usr/include
g++ main.o -o sfml-app -L /usr/lib -lsfml-graphics -lsfml-window -lsfml-system


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Elements of the SFML/Audio header files cause the linker to crash
« Reply #1 on: July 11, 2022, 08:16:44 pm »
You also need to link the SFML Audio module: -lsfml-audio
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ArchBTW

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Elements of the SFML/Audio header files cause the linker to crash
« Reply #2 on: July 11, 2022, 08:41:38 pm »
Thanks!

 

anything