joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.79k stars 382 forks source link

Missing symbols when linking with system-installed SDL2 #3212

Open OPNA2608 opened 2 years ago

OPNA2608 commented 2 years ago

Code of Conduct & Contributing Guidelines

Have you checked that no other similar bug report(s) already exists?

What operating system(s) this bug have occurred on?

Linux (NixOS 21.11) x86_64

What version(s) of DOSBox-X have this bug?

0.83.21, confirmed as far back as 0.83.9

Describe the bug

Linking against the system-installed SDL2 errors out with missing symbol errors.

Build log line that causes the error is the final linking step:

g++  -g -std=gnu++14  -O2 -msse  -Wall   -Wextra   -Wunused   -pedantic   -Wlogical-op   -Wsign-promo   -Wconversion-null   -Wno-deprecated-declarations   -Wno-implicit-fallthrough   -Wno-strict-aliasing   -Wno-missing-field-initializers   -Wno-format-zero-length   -Wno-address-of-packed-member   -Wno-int-to-void-pointer-cast  -I/build/source -I/build/source/vs/sdlnet/linux-host/include -I/build/source/vs/sdlnet/linux-host/include/SDL -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L   -L/build/source/vs/sdlnet/linux-host/lib -o dosbox-x dosbox.o  debug/libdebug.a dos/libdos.a shell/libshell.a builtin/libbuiltin.a ints/libints.a hardware/serialport/libserial.a hardware/parport/libparallel.a libs/porttalk/libporttalk.a gui/libgui.a libs/gui_tk/libgui_tk.a hardware/libhardware.a cpu/libcpu.a hardware/reSID/libresid.a fpu/libfpu.a gui/libgui.a misc/libmisc.a output/liboutput.a hardware/mame/libmame.a libs/zmbv/libzmbv.a libs/decoders/internal/libopusint.a aviwriter/libaviwriter.a  libs/xBRZ/libxbrz.a libs/mt32/libmt32.a libs/fluidsynth/libfluidsynth.a -L/nix/store/ix4c8g8wz33harx4qfqfhx549380nm8r-SDL2-2.0.14/lib -Wl,-rpath,/nix/store/ix4c8g8wz33harx4qfqfhx549380nm8r-SDL2-2.0.14/lib -Wl,--enable-new-dtags -lSDL2 -L/nix/store/rl6f0lkf5ydkixaczy68gyg0hriwq1cv-freetype-2.11.1/lib -lfreetype -lz -lpng -lz -lpcap -L/nix/store/nyl940gys6x2q0g465vpz7ay1gng14f6-libslirp-4.6.1/lib -L/nix/store/lirhad3vmiwbs6jwffdpz2cgyskwgivs-glib-2.70.2/lib -lslirp -lglib-2.0 -lX11 -lfluidsynth -lGL

Missing -ldl for dlclose:

/nix/store/cdm6zywd51mbabxhklsixwcskv4n70s3-binutils-2.35.2/bin/ld: hardware/libhardware.a(glide.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/nix/store/cdm6zywd51mbabxhklsixwcskv4n70s3-binutils-2.35.2/bin/ld: /nix/store/s9qbqh7gzacs7h68b2jfmn9l6q4jwfjz-glibc-2.33-59/lib/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

After forcing -ldl into linker flags, also missing -lpthread for pthread_create:

/nix/store/cdm6zywd51mbabxhklsixwcskv4n70s3-binutils-2.35.2/bin/ld: dos/libdos.a(cdrom_image.o): undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
/nix/store/cdm6zywd51mbabxhklsixwcskv4n70s3-binutils-2.35.2/bin/ld: /nix/store/s9qbqh7gzacs7h68b2jfmn9l6q4jwfjz-glibc-2.33-59/lib/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

None such errors occur when building against the vendored SDL1.x.

Expected behavior

All libraries required for the used functions should be detected & have their required linker flags added by the configure tool.

Steps to reproduce the behaviour

  1. Link with system-installed SDL2 on Linux

Used configuration

No response

Emulator log

n/a

Additional context

I'm not using your build scripts but manually calling all the autotool & make stuff as part of a staged packaging script. I don't think it ends up being too different from the way your scripts are working though?

https://github.com/OPNA2608/nixpkgs/blob/init/dosbox-x/pkgs/misc/emulators/dosbox-x/default.nix

You can see here that my workaround is to hack -ldl -lpthread into the compiler wrapper's LDFLAGS.

rderooy commented 2 years ago

Do the build scripts work for you?

In any case, the build works fine on both RedHat/Fedora and Ubuntu distros so it is likely something specific to your distro.

OPNA2608 commented 2 years ago

Still errors when using the build scripts.

Here's the build log when using the build scripts.

joncampbell123 commented 2 years ago

You'll need to add "-ldl" to the linker flags, glide.o has code to load a *.so shared object at runtime.

grapeli commented 2 years ago

This should happen automatically. Without additional intervention. Dosbox-x requires dlclose. hardware/libhardware.a(glide.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'

His build is unusual. Since it builds without alsa. Though I don't know if it's intentional? -ldl is added by the way, "thanks" to alsa.

edit: It's no good mixing SDL_net with SDL2. SDL2_net must be used for SDL2.

OPNA2608 commented 2 years ago

Adding ALSA indeed "fixes" it like @grapeli said. Truth be told I didn't know it was needed? I have nothing to test audio with rn but it still seems to connect to Pulseaudio so I didn't think much of it. If it's not supported/intended, then the configure script should prolly error out if it's missing.

Regardless of that, the configure script should really add the libraries needed for the ALSA-independent codebase.

I can't comment on the SDL*_net stuff.

grapeli commented 2 years ago

@OPNA2608 ALSA is not required. It is useful (even indispensable) when you want to use an external MIDI source - fluidsynth, timidity, mt32 or ALSA midi itself. I emphasize that this does not apply to the fluidsynth and mt32 libraries linked to dosbox-x.

SDL2 can use pulse, jack, pipewire (probably from 2.0.16), oss and of course alsa. 99% of the distribution is built anyway by pulseaudio, pipewire, jack with possible alsa usage. So every distribution includes libasound.so anyway (with no header files installed by default at most).