Search code examples
c++audiosfml

My c++ program crashes instantly when using SFML/Audio.hpp (Building works)


I am using the following c++ compiler

  • MinGW-W64-builds-4.3.4

on Windows 10 with the following SFML library

  • SFML-2.5.1-windows-gcc-7.3.0-mingw-32-bit

and CLion 2021.2 Build #CL-212.4746.93

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.20)
project(SFML_Audio_Error)

set(CMAKE_CXX_STANDARD 14)

add_executable(SFML_Audio_Error main.cpp)

set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR C:/SFML/lib/cmake/SFML)
find_package(SFML COMPONENTS system window graphics audio network REQUIRED)

include_directories(c:/SFML/include)

target_link_libraries(SFML_Audio_Error sfml-system sfml-window sfml-graphics sfml-audio)

And I use the following Code:

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

int main() {
    sf::Music test;
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

When taking away the line

sf::Music test;

the code works normally, when using the line I get the following Clion error

Process finished with exit code -1073741515 (0xC0000135)

This is my first stackoverflow post because I really need some advice I couldnt find anything online either, except importing .dll files but there were no clear instructions on how to do that. Im not even sure if thats my problem. If someone can help me out im really grateful, I just wanted to add some funny sound effects to my programs. I hope i provided everything you need to know :).

*Edit:

I added 2 .dll files to the working Directory:

Working Directory


Solution

  • So I solved the issue. Thanks to the help of Retired Ninja. I put the openal32.dll file into the same directory as the executable (.exe) this resolved the issue and i can play sound now.

    Thanks again all of you. :)

    Picture of the working Directory with the .dll