1
Audio / Re: undefined reference when using audio to play music
« on: December 02, 2022, 10:06:55 am »If you use git master (which is SFML 3 WIP and not SFML 2.6), you should use namespaces.
And if you don't link SFML dynamically, you can also get rid of the line at the bottom.
You don't need to set the standard globally if if you set the compile feature below.
For example:cmake_minimum_required(VERSION 3.25.0)
# Setup
project(RedC LANGUAGES CXX) # Must match the main file name
set(EXECUTABLE_NAME "RedC") # Executable name
set(LANGUAGE CXX)
set(PROJECT_SOURCES # *.cpp that was made
${PROJECT_NAME}.cpp # Main file
int/src/logger.cpp # Custom logger
int/src/object.cpp # Base for any object in game that can be drawn
int/src/enemyCharacter.cpp # Enemy object
int/src/playerCharacter.cpp # Player objects
int/src/staticObj.cpp # Not interactable object (wall)
int/src/interactableObj.cpp # Interactable object (chest, loot, door)
int/src/characterObj.cpp # Base for a character
)
set(PROJECT_HEADERS # *.hpp that was made
int/hdr/logger.hpp # Custom logger
int/hdr/object.hpp
int/hdr/enemyCharacter.hpp
int/hdr/playerCharacter.hpp
int/hdr/staticObj.hpp
int/hdr/interactableObj.hpp
int/hdr/characterObj.hpp
)
include_directories( # dirs to include (.hpp)
int/hdr/ # Allows for ease of use when using custom hpp files
)
add_executable(${EXECUTABLE_NAME} ${PROJECT_NAME} ${PROJECT_SOURCES} ${PROJECT_HEADERS})
# Copying assets
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/assets/ $<TARGET_FILE_DIR:${PROJECT_NAME}>/assets/)
# SFML
option(BUILD_SHARED_LIBS OFF)
include(FetchContent)
FetchContent_Declare(SFML GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_TAG master) # 2.6.x
FetchContent_MakeAvailable(SFML)
target_link_libraries(${PROJECT_NAME} PRIVATE SFML::Graphics SFML::Audio SFML::Network)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23)
install(TARGETS ${PROJECT_NAME})
You could additionally also use globbing to get all the files without having to list them all, but that's mostly a question of preference.
That does look cleaner, thanks. The reason I'm using the master version is that on my pc I have an AMD GPU, if I don't use the master version it gives an error.
But now I'm having an issue when trying to run it on my laptop, it needs the openal32.dll next to the executable, but I thought it linked static libraries. If I don't place the DLL next to the EXE it crashes the program when using the audio library. I currently can't confirm this, but I think I did not have to do this when running it on my pc.
The error: Process finished with exit code -1073741515 (0xC0000135); after looking for this it is a missing DLL error.