libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.
zlib License
433 stars 146 forks source link

Static linking of dependent program with CMake fails in Autotools build with --disable-foo-shared #411

Closed smcv closed 2 years ago

smcv commented 2 years ago

To reproduce:

(The same problem probably exists for dependencies other than libflac, I haven't tried.)

Expected result: main_shared is linked statically, as far as is possible.

Actual result:

[3/4] Linking C executable main_static
FAILED: main_static 
: && /usr/bin/cc   CMakeFiles/main_static.dir/main.c.o -o main_static  /usr/lib/x86_64-linux-gnu/libSDL2.a  /usr/lib/x86_64-linux-gnu/libSDL2_mixer.a  -lm -ldl  -lasound -lm -ldl -lpthread -lpulse-simple -pthread -lpulse -pthread  -lX11 -lXext -lXcursor -lXinerama -lXi -lXfixes -lXrandr -lXss -lXxf86vm -ldrm -lgbm -lwayland-egl -lwayland-client -lwayland-cursor -lxkbcommon -ldecor-0 -lpthread -lrt && :
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libSDL2_mixer.a(music_flac.o): undefined reference to symbol 'FLAC__stream_decoder_get_total_samples'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libFLAC.so.8: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
[4/4] Linking C executable main_shared

I think this is because configure.ac has two code paths for mandatory dependencies:

SDL_image and SDL_ttf do not have this bug: they add mandatory dependencies to IMG_LIBS or TTF_LIBS as appropriate, and sdl2_foo-config.cmake lists both PC_LIBS and IMG_LIBS or TTF_LIBS in its extra_static_libraries variable.