SFML/cmake-sfml-project

OpenAL32 module created without symbols

Closed this issue · 7 comments

I'm using the CMakeLists.txt template from the master branch with this only relevant modification:

target_link_libraries(CMakeSFMLProject PRIVATE sfml-graphics sfml-audio)
file(GLOB DATA
  "${PROJECT_SOURCE_DIR}/data/*"
)
file(COPY ${DATA} DESTINATION "${PROJECT_BINARY_DIR}")

In main.cpp I have this relevant code:

sf::SoundBuffer buf;
if (!buf.loadFromFile("sound.wav"))
  return -1;
sf::Sound sound;
sound.setBuffer(buf);
sound.play();

Compiling it on WIndows 10 with MSVC on x64 Native Tools Command Prompt for VS 2022:

cmake -S . -B build
cmake --build build --config Release
.\build\bin\Release\CMakeSFMLProject.exe

The exe is built, but when I try to run it, Windows gives me the helpful error message: "The app could not be initialized correctly (0xc000007b)".
Running it in Visual Studio, the debug output yields (in portuguese):

"CMakeSFMLProject.exe" (Win32): Carregado "C:\Users\<long_path>\SFML\out\build\x64-release-windows\bin\openal32.dll". O módulo foi criado sem símbolos.
"CMakeSFMLProject.exe" (Win32): Não carregado "C:\Users\<long_path>\SFML\out\build\x64-release-windows\bin\openal32.dll"

Which translates to something like:

"CMakeSFMLProject.exe" (Win32): Loaded "C:\Users\<long_path>\SFML\out\build\x64-release-windows\bin\openal32.dll". The module was created without symbols.
"CMakeSFMLProject.exe" (Win32): Not loaded "C:\Users\<long_path>\SFML\out\build\x64-release-windows\bin\openal32.dll"

The error does not occur if I don't use/link sfml-audio.

I was able to make OpenAL32 work with the following script:

# Add OpenAL32 (required by sfml-audio on Windows)
if(WIN32)
    set(OPENAL32_URL "https://openal-soft.org/openal-binaries/openal-soft-1.23.1-bin.zip")
    set(OPENAL32_ZIP_PATH "${CMAKE_BINARY_DIR}/openal-soft.zip")
    set(OPENAL32_DIR "${CMAKE_BINARY_DIR}/OpenAL32")
    set(OPENAL32_PATH "${OPENAL32_DIR}/openal-soft-1.23.1-bin")
    if(NOT EXISTS ${OPENAL32_DIR})
        file(DOWNLOAD ${OPENAL32_URL} ${OPENAL32_ZIP_PATH})
        execute_process(COMMAND powershell -Command "Expand-Archive \"${OPENAL32_ZIP_PATH}\" -DestinationPath \"${OPENAL32_DIR}\"")
        file(RENAME "${OPENAL32_PATH}/bin/Win64/soft_oal.dll" "${OPENAL32_PATH}/bin/Win64/OpenAL32.dll")
        file(REMOVE ${OPENAL32_ZIP_PATH})
    endif()
    add_library(OpenAL32 SHARED IMPORTED)
    set_target_properties(OpenAL32 PROPERTIES
        IMPORTED_LOCATION "${OPENAL32_PATH}/bin/Win64/OpenAL32.dll"
        IMPORTED_IMPLIB "${OPENAL32_PATH}/libs/Win64/OpenAL32.lib"
    )
    target_link_libraries(CMakeSFMLProject PRIVATE OpenAL32)
endif()
if (WIN32 AND BUILD_SHARED_LIBS)
    add_custom_command(TARGET CMakeSFMLProject POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:CMakeSFMLProject> $<TARGET_FILE_DIR:CMakeSFMLProject> COMMAND_EXPAND_LISTS)
endif()

But it requires fetching from openal-soft.org, which is slow and I don't know if it would violate any licenses.
Since the dll from openal-soft works, I think the openal binary in ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<BOOL:${ARCH_64BITS}>,x64,x86>/openal32.dll might be the problem.

19e8b5c

This commit from 2 weeks ago is supposed to fix this. Is that .dll being copied into the same directory as your executable?

Yes, and if I delete it manually from the executable directory, the error message is different:
"The code execution could not continue because OpenAL32.dll was not found. [ ... ]" (translated from portuguese)
As opposed to:
"The app could not be initialized correctly (0xc000007b)" (translated from portuguese)

Could the problem be that we're not also copying the corresponding .lib file? Could that explain the error about the module being created without symbols?

I tried copying the .lib file with this script (I'm not that good with CMake, sorry):

if(WIN32)
    add_custom_target(OpenAL32Copy
        COMMENT "Copy OpenAL LIB"
        COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/lib
        COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/libs-msvc/$<IF:$<BOOL:${ARCH_64BITS}>,x64,x86>/openal32.lib ${CMAKE_BINARY_DIR}/lib
        BYPRODUCTS ${CMAKE_BINARY_DIR}/lib/openal32.lib
        VERBATIM
    )
    add_library(OpenAL32 SHARED IMPORTED)
    add_dependencies(OpenAL32 OpenAL32Copy)
    set_target_properties(OpenAL32 PROPERTIES
        IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/bin/openal32.dll"
        IMPORTED_IMPLIB "${CMAKE_BINARY_DIR}/lib/openal32.lib")
    add_custom_command(
        TARGET CMakeSFMLProject 
        COMMENT "Copy OpenAL DLL"
        DEPENDS ${CMAKE_BINARY_DIR}/lib/openal32.lib
        PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<BOOL:${ARCH_64BITS}>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:CMakeSFMLProject >
        VERBATIM)
    target_link_libraries(CMakeSFMLProject PRIVATE OpenAL32)
endif()

Same result as copying just the .dll, but I might have done something wrong in the process of copying it (the .lib).

About the module being created without symbols, I really couldn't find much about it on the internet, except that it might mean there is no debug info available and it "shouldn't be a concern".

Please test out #25 and let me know if that fixes your problem.

That was quick, thank you very much! Amazing experience for my first issue.

Thanks for the great bug report!