Fixed bug 5105 - sndio support not working in dynamic mode (dlopen) Giovanni Bajo The CMake build system supports several audio frameworks for Linux: one of them is sndio. All frameworks can be built with "runtime linking" (that is, using dlopen to load the library at runtime). In sdlchecks.cmake, there's code to do the same with sndio: ================================================================= # Requires: # - n/a # Optional: # - SNDIO_SHARED opt # - HAVE_DLOPEN opt macro(CheckSNDIO) if(SNDIO) # TODO: set include paths properly, so the sndio headers are found check_include_file(sndio.h HAVE_SNDIO_H) find_library(D_SNDIO_LIB sndio) if(HAVE_SNDIO_H AND D_SNDIO_LIB) set(HAVE_SNDIO TRUE) file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c) set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES}) set(SDL_AUDIO_DRIVER_SNDIO 1) if(SNDIO_SHARED) if(NOT HAVE_DLOPEN) message_warn("You must have SDL_LoadObject() support for dynamic sndio loading") else() FindLibraryAndSONAME("sndio") set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"") set(HAVE_SNDIO_SHARED TRUE) endif() else() list(APPEND EXTRA_LIBS ${D_SNDIO_LIB}) endif() set(HAVE_SDL_AUDIO TRUE) endif() endif() endmacro() ================================================================= The feature is gated by an option called SNDIO_SHARED. It is also fully implemented in SDL_sndioaudio.c Unfortunately, it seems there is a missing line in CMakeLists.txt, so SNDIO_SHARED is not defined: ====================================================================== set_option(ALSA "Support the ALSA audio API" ${UNIX_SYS}) dep_option(ALSA_SHARED "Dynamically load ALSA audio support" ON "ALSA" OFF) set_option(JACK "Support the JACK audio API" ${UNIX_SYS}) dep_option(JACK_SHARED "Dynamically load JACK audio support" ON "JACK" OFF) set_option(ESD "Support the Enlightened Sound Daemon" ${UNIX_SYS}) dep_option(ESD_SHARED "Dynamically load ESD audio support" ON "ESD" OFF) set_option(PULSEAUDIO "Use PulseAudio" ${UNIX_SYS}) dep_option(PULSEAUDIO_SHARED "Dynamically load PulseAudio support" ON "PULSEAUDIO" OFF) set_option(ARTS "Support the Analog Real Time Synthesizer" ${UNIX_SYS}) dep_option(ARTS_SHARED "Dynamically load aRts audio support" ON "ARTS" OFF) set_option(NAS "Support the NAS audio API" ${UNIX_SYS}) set_option(NAS_SHARED "Dynamically load NAS audio API" ${UNIX_SYS}) set_option(SNDIO "Support the sndio audio API" ${UNIX_SYS}) set_option(FUSIONSOUND "Use FusionSound audio driver" OFF) dep_option(FUSIONSOUND_SHARED "Dynamically load fusionsound audio support" ON "FUSIONSOUND" OFF) ====================================================================== You can see that all frameworks define a "dep_option" NAME_SHARED, and SNDIO is the only one where the option is missing. This means that runtime loading of sndio is never activated. If sndio is found at configuration time, it is always activated in "linked" mode, so that the final binary will have a load-time dependency with libsdnio. This is unfortunate. To fix the problem, it is sufficient to add this line: dep_option(SNDIO_SHARED "Dynamically load the sndio audio API" ${UNIX_SYS} ON "SNDIO" OFF) I've verified that this fixes the bug, and sndio can now be dynamically loaded as expected.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5f1d55..fc0fd74 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -354,6 +354,7 @@ dep_option(ARTS_SHARED "Dynamically load aRts audio support" ON "ARTS" O
set_option(NAS "Support the NAS audio API" ${UNIX_SYS})
set_option(NAS_SHARED "Dynamically load NAS audio API" ${UNIX_SYS})
set_option(SNDIO "Support the sndio audio API" ${UNIX_SYS})
+dep_option(SNDIO_SHARED "Dynamically load the sndio audio API" ${UNIX_SYS} ON "SNDIO" OFF)
set_option(FUSIONSOUND "Use FusionSound audio driver" OFF)
dep_option(FUSIONSOUND_SHARED "Dynamically load fusionsound audio support" ON "FUSIONSOUND" OFF)
set_option(LIBSAMPLERATE "Use libsamplerate for audio rate conversion" ${UNIX_SYS})