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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Lenny

Pages: [1]
1
Audio / undefined reference when using audio to play music
« on: November 26, 2022, 10:54:45 pm »
I've been trying to play music using SFML but the program does not compile when I try this.
Opening and playing the music:
sf::Music music;
music.openFromFile("assets/music/FLAC/password-infinity.flac");
music.play();
I'm using CMake / G++ (12.2.0) to compile, the CMake configuration is as follows:
cmake_minimum_required(VERSION 3.25.0)
set(CMAKE_CXX_STANDARD 23)

# Setup
project(main) # Must match the main file name
set(EXECUTABLE_NAME "main") # Executable name

set(PROJECT_SOURCES # *.cpp that was made
        ${PROJECT_NAME}.cpp # Main file
        int/src/logger.cpp # Custom logger
        )

set(PROJECT_HEADERS # *.hpp that was made
        int/hdr/logger.hpp # Custom logger
        )

include_directories( # dirs to include (.hpp)
                int/hdr/ # Allows for ease of use when using custom hpp files
                ext/SFML/include/
                )

link_directories( # dirs to link (.a)
                ext/SFML/lib/
                )

# SFML
set(SFML_STATIC_LIBRARIES TRUE) # Using a static built
set(SFML_DIR ext/SFML/cmake) # SFML CMake files
find_package(SFML 2.5 COMPONENTS system window graphics network audio REQUIRED) # Just getting everything

set(SFML_LIBRARIES
        sfml-graphics-s # Needs to be first
        sfml-window-s # Needs to be second
        sfml-audio-s # Needs to be before system
        sfml-network-s # Needs to be before system
        sfml-main # Needs to be before system
        sfml-system-s # Needs to be last
        )

set(SFML_DEPENDENCIES
        opengl32 # window, graphics
        freetype # graphics
        winmm # window, system
        gdi32 # window
        vorbisenc # audio
        vorbisfile # audio
        vorbis # audio
        flac # audio
        openal32 # audio
        ogg # audio
        ws2_32 # network
        )

# Build
add_executable(${EXECUTABLE_NAME} ${PROJECT_NAME} ${PROJECT_SOURCES} ${PROJECT_HEADERS})
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES}) # SFML first, dependencies second
I've built SFML from source since I'm using a different setup from the precompiled versions. As for the order, the one I use is what I was able to find online.

Pages: [1]