I'm getting into building an application using the C++ SFML library. (I'm on Windows using CLion and CMake)
Currently, my code is looking like this:
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML Audio Test");
sf::Music music{};
if (!music.openFromFile("res/test.mp3")) {
std::cout << "Failed to load music" << std::endl;
return 1;
}
if (music.getStatus() != sf::Music::Status::Playing) {
std::cout << "Music is not playing" << std::endl;
return 1;
}
music.play();
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
}
return 0;
}
However, when I try to run this program, the window never opens, sound/music never plays, and I get this in my console.
D:\PATH\NAME.exe
Process finished with exit code -1073741515 (0xC0000135)
When I remove the code related to music (sf::Music music{}; --> music.play()
, the window does open and the program runs correctly.
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.26)
project(adaptive_audio)
set(CMAKE_CXX_STANDARD 17)
add_executable(adaptive_audio main.cpp)
set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "./libraries/SFML/lib/cmake/SFML")
find_package(SFML COMPONENTS system audio network graphics window REQUIRED)
include_directories("./libraries/SFML/include/SFML")
target_link_libraries(adaptive_audio sfml-system sfml-audio sfml-network sfml-graphics sfml-window)
What am I doing wrong?