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

Author Topic: Undefined reference to sf:Music  (Read 10004 times)

0 Members and 1 Guest are viewing this topic.

Fnak

  • Newbie
  • *
  • Posts: 22
    • View Profile
Undefined reference to sf:Music
« on: March 19, 2014, 10:38:38 pm »
Hello, just recently got into SFML and been creating sprites and textures and made them move around and whatnot (a very little and simple game basically).

I wanted to add music through sf:Music but I just get the errors undefined reference to:
sf:Music::Music()
sf:Music::openFromFile(std::string const&)
sf:SoundStream::play()
sf::Music::~Music()

my code looks a little something like this:

    sf::Music music;
    if (!music.openFromFile("Content/batman.wav"))
        return -1; // error
    music.play();


and my include statements are:


#include <SFML/Audio.hpp>
#include <iostream>

(not sure if iostream is necessary or not but whatever).

I've linked SFML2.1/Include/ under Search Directories>Compiler and SFML2.1/lib/ under Search Directories>Linker.

Can't get it to work, anything I'm doing wrong here or?

Thanks in advance!

Edit: Using codeblocks if it wasn't clear enough
« Last Edit: March 19, 2014, 11:34:18 pm by Fnak »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Undefined reference to sf:Music
« Reply #1 on: March 19, 2014, 11:08:41 pm »
You must link sfml-audio.
Laurent Gomila - SFML developer

Fnak

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Undefined reference to sf:Music
« Reply #2 on: March 19, 2014, 11:23:57 pm »
I went to my projects Build Options>Linker Settings and added libsfml-audio.a, and then I got the error message saying: Undefined reference to '_Unwind_Resume'.

Am I doing this right becuase I have no idea anymore.

I thought everything was set and clear when I linked /include and /lib
« Last Edit: March 19, 2014, 11:32:50 pm by Fnak »

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Undefined reference to sf:Music
« Reply #3 on: March 20, 2014, 01:00:44 am »
What IDE are you using?
Current Projects:
Technoport

Fnak

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Undefined reference to sf:Music
« Reply #4 on: March 20, 2014, 08:46:38 am »
I'm currently using codeblocks with MinGW

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Undefined reference to sf:Music
« Reply #5 on: March 20, 2014, 08:55:41 am »
then I got the error message saying: Undefined reference to '_Unwind_Resume'.
You're most likely linking against an incompatible SFML version regarding your compiler. If SFML wasn't built with the same compiler, then you can't link it properly.
Rebuild SFML with your current compiler. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Fnak

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Undefined reference to sf:Music
« Reply #6 on: March 20, 2014, 09:07:38 am »
I don't know... I've downloaded the new latest version of SFML and updated codeblocks and linked everything properly... I keep getting the same error.

Am I actually doing everything correctly, maybe missing out on one point? All I do is link the include folder under Search Directories>Compiler and the lib folder under Search Directories>Linker using Global Compiler Settings. Do I need to link in the projects build options too??

I mean, everything else seem to work, I can create sprites and textures etc, but sf::Music and sf::SoundBuffer gets undefined references.
« Last Edit: March 20, 2014, 09:12:08 am by Fnak »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Undefined reference to sf:Music
« Reply #7 on: March 20, 2014, 09:52:23 am »
You downloaded SFML, does that mean you didn't compile it yourself?

What version of Code::Blocks do you have. What's the compiler version? What SFML package did you download?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Fnak

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Undefined reference to sf:Music
« Reply #8 on: March 20, 2014, 09:58:02 am »
I downloaded codeblocks-13.12mingw-setup.exe (http://www.codeblocks.org/downloads/26#windows) which should include the latest version of the mingw compiler aswell. The SFML package I downloaded was the 2.1 version (http://www.sfml-dev.org/download/sfml/2.1/) GCC 4.7 MinGW (DW2) - 32 bits

I believe that's all I need, right?
« Last Edit: March 20, 2014, 10:00:29 am by Fnak »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Undefined reference to sf:Music
« Reply #9 on: March 20, 2014, 10:11:27 am »
Well read again what the Code::Blocks description says:
Quote
The codeblocks-13.12mingw-setup.exe file includes the GCC compiler and GDB debugger from TDM-GCC (version 4.7.1, 32 bit).

And then we read again what the download section lists:
Quote
GCC 4.7 TDM (SJLJ) - 32 bits
GCC 4.7 TDM (SJLJ) - 64 bits
GCC 4.7 MinGW (DW2) - 32 bits

So yeah, MinGW != TDM. ;)
Apparently they changed things, so if you got the 13.12mingw-setup you should be able to use the 4.7 TDM package.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Fnak

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Undefined reference to sf:Music
« Reply #10 on: March 20, 2014, 10:16:33 am »
Oh, OK! I'll try it out as soon as I get home, thanks!

 

anything