Skip to content

Fix Linux Linker Error: Undefined reference to dlclose in miniaudio_impl #18

Description

@wrju333

Title

Fix Linux Linker Error: Undefined reference to dlclose in miniaudio_impl

Description

Hi Sarah! First of all, thank you for your amazing work on InmarScope. I successfully compiled and ran the application natively on Linux (Xubuntu 20.04), but the compilation fails at the very last step ([346/346]) due to a missing linker flag for Linux's dynamic loading library.
Since miniaudio requires dynamic loading to interface with Linux audio drivers, GCC/Clang needs an explicit -ldl flag passed during the linking stage. On Windows/MSYS2, this functionality is implicit, which is why it works perfectly there but breaks on Linux.

Exact Linker Error Log

[346/346] Linking CXX executable InmarScope
FAILED: InmarScope
... -o InmarScope ... -lpthread && :
/usr/bin/ld: CMakeFiles/InmarScope.dir/src/audio/miniaudio_impl.cpp.o: undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

The Solution (Permanent CMake Fix)

To permanently fix this for all Linux users without impacting Windows builds, the following platform check can be appended to the bottom of the main CMakeLists.txt file (or wherever the InmarScope target linking is defined):

if(UNIX AND NOT APPLE)
target_link_libraries(InmarScope dl)endif()

This guarantees that -ldl is appended properly at the end of the compiler's link command on Linux systems. Thank you again for keeping this project moving forward, looking forward to the upcoming RSP input source support!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions