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

Author Topic: C++ code not compiling.  (Read 1713 times)

0 Members and 1 Guest are viewing this topic.

pppizzacat

  • Newbie
  • *
  • Posts: 2
    • View Profile
C++ code not compiling.
« on: August 12, 2020, 07:01:21 am »
Hello! I'm completely new to SFML, and I just installed it on Windows Subsystem for Linux (specifically Ubuntu) using the "sudo apt-get install libsfml-dev" command in my terminal. I created a very basic program (that was mostly copied from the SFML tutorials) to just test sound playback, and my program doesn't want to compile.

Here's my program:
#include <SFML/Audio.hpp>

int main() {

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

}

and here's my terminal output:
root@ADAM-FLEX:/mnt/c/Users/nucle/Desktop/final project stuffz# g++ -g -Wall sfml.cpp -o test.exe
/tmp/ccrRq561.o: In function `main':
/mnt/c/Users/nucle/Desktop/final project stuffz/sfml.cpp:5: undefined reference to `sf::Music::Music()'
/mnt/c/Users/nucle/Desktop/final project stuffz/sfml.cpp:6: undefined reference to `sf::Music::openFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/mnt/c/Users/nucle/Desktop/final project stuffz/sfml.cpp:8: undefined reference to `sf::SoundStream::play()'
/mnt/c/Users/nucle/Desktop/final project stuffz/sfml.cpp:8: undefined reference to `sf::Music::~Music()'   
/mnt/c/Users/nucle/Desktop/final project stuffz/sfml.cpp:5: undefined reference to `sf::Music::~Music()'   
collect2: error: ld returned 1 exit status


I'm currently using Windows 10.
If anyone can give me any advice, it would be greatly appreciated!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: C++ code not compiling.
« Reply #1 on: August 12, 2020, 09:44:51 am »
You must link to the SFML audio library.

-lsfml-audio

Please read the tutorial for more details.
https://www.sfml-dev.org/tutorials/2.5/start-linux.php
Laurent Gomila - SFML developer

pppizzacat

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: C++ code not compiling.
« Reply #2 on: August 12, 2020, 10:41:53 am »
I tried compiling in the way shown in the tutorial and linking the library, but now I'm getting this in my console whenever I execute my program.

An internal OpenAL call failed in SoundStream.cpp(472).
Expression:
   alSourceUnqueueBuffers(m_source, 1, &buffer)
Error description:
   AL_INVALID_OPERATION
   The specified operation is not allowed in the current state.


This just repeats over and over.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: C++ code not compiling.
« Reply #3 on: August 12, 2020, 11:50:20 am »
Are you sure that you have a valid audio device available in your "Windows Subsystem for Linux"? Are you able to compile/run the examples provided with SFML?
Laurent Gomila - SFML developer

 

anything