Author Topic: Building SDL2 (and later linking against it)  (Read 3404 times)

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Building SDL2 (and later linking against it)
« on: February 06, 2022, 06:55:08 am »
OK, I almost have SDL2 building. Using this configure command,
Code: [Select]
sh ../SDL2-os2/configure 'LDFLAGS=-Zomf -Zhigh-mem -Zmap -Zbin-files' LIBS=-lcx 'CPPFLAGS=-idirafter=k:/usr/include/os2tk45'
Configure outputs,
Code: [Select]
SDL2 Configure Summary:
Building Shared Libraries
Building Static Libraries
Enabled modules : atomic audio video render events joystick haptic hidapi sensor power filesystem threads timers file loadso cpuinfo assembly
Assembly Math   : mmx 3dnow sse
Audio drivers   : OS/2
Video drivers   : OS/2
Input drivers   :
Enable virtual joystick APIs : YES
Using libsamplerate : NO
Using libudev       : NO
Using dbus          : NO
Using ime           : NO
Using ibus          : NO
Using fcitx         : NO

So it looks like it is pulling hidapi for joystick use. Possibly the OS/2 joystick support needs disabling.
Unluckily the build dies here,
Code: [Select]
libtool: compile:  gcc.exe -g -O3 -idirafter=k:/usr/include/os2tk45 -DUSING_GENERATED_CONFIG_H -Iinclude -IK:/work/SDL2-os2/include -idirafter K:/work/SDL2-os2/src/video/khronos -mmmx -m3dnow -msse -Wall -fno-strict-aliasing -DOS2EMX_PLAIN_CHAR -Wdeclaration-after-statement -Werror=declaration-after-statement -D_REENTRANT -I/@unixroot/usr/include/libusb-1.0 -MMD -MT build/SDL_os2dive.lo -c K:/work/SDL2-os2/src/video/os2/SDL_os2dive.c  -DDLL_EXPORT -DPIC -o build/.lib/SDL_os2dive.o
K:/work/SDL2-os2/src/video/os2/SDL_os2dive.c:27:10: fatal error: mmioos2.h: No such file or directory
   27 | #include <mmioos2.h>
      |          ^~~~~~~~~~~
compilation terminated.
make: *** [build/SDL_os2dive.lo] Error 1

The CPPFLAGS=-idirafter=k:/usr/include/os2tk45 should put the toolkit last in the include path, yet mmioos2.h isn't found.

Jochen Schäfer

  • Sr. Member
  • ****
  • Posts: 306
  • Karma: +27/-0
    • View Profile
Re: Building SDL2 (and later linking against it)
« Reply #1 on: February 07, 2022, 03:24:42 pm »
I use the following script for autoconf:
Code: [Select]
#!/@unixroot/usr/bin/ash
autoreconf -fiv

export LDFLAGS=" -Zhigh-mem -Zomf -Zargs-wild -Zargs-resp -lcx -lmmpm2"
export CFLAGS="-idirafter /@unixroot/usr/include/os2tk45"

./configure --disable-arts --disable-esd --disable-nas --enable-sse2=yes --enable-sse3=yes --disable-rpath --enable-static --enable-shared --prefix=/@unixroot/usr/local

make clean
make -j5

For cmake, I use the following:
Code: [Select]
export LDFLAGS=" -Zhigh-mem -Zomf -Zargs-wild -Zargs-resp -lcx -lmmpm2"
export CFLAGS="-O2 -g -march=i686 -idirafter /@unixroot/usr/include/os2tk45"
export CXXFLAGS="-O2 -g -march=i686"
export FFLAGS="-O2 -g -march=i686"
export FCFLAGS="-O2 -g -march=i686"

cmake  -DCMAKE_INSTALL_PREFIX:PATH=/@unixroot/usr/local \
    -DSDL_DLOPEN=ON \
    -DSDL_ARTS=OFF \
    -DSDL_ESD=OFF \
    -DSDL_NAS=OFF \
    -DSDL_LIBDECOR_SHARED=ON \
    -DSDL_SSE2=OFF \
    -DSDL_SSE3=OFF \
    -DSDL_RPATH=OFF \
    -DSDL_STATIC=ON \
    -DSDL_STATIC_PIC=ON \
    -DSDL_LIBC=ON \
    -DSDL_TEST=ON \
    -DBUILD_SHARED_LIBS:BOOL=ON \
    -DCMAKE_BUILD_TYPE=Debug \
    d:/work/sdl2/sdl2-os2 -B . -S d:/work/sdl2/sdl2-os2

make clean
make -j5

Hope, it helps.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: Building SDL2 (and later linking against it)
« Reply #2 on: February 07, 2022, 08:54:57 pm »
OK, I had a brain fart with -dirafter and it seems this configure script doesn't honour the LIBS environment.
Currently using
Code: [Select]
sh ../SDL2-os2/configure  -prefix=h:/tmp/sdl2 'LDFLAGS=-Zomf -Zhigh-mem -Zmap -Zbin-files -lcx -lmmpm2' 'CPPFLAGS=-idirafter g:/os2tk45/h'
and build dies with,
Code: [Select]
weakld: error: Unresolved symbol (UNDEF) '_SDL_DUMMY_JoystickDriver'.
weakld: info: The symbol is referenced by:
    H:\tmp\ldconv_SDL_joystick_o_f927620154a31ad188.obj
etc.
Seems a conflict with the hidapi joystick support with the dummy joystick support.

About your flags. -Zargs-* don't make sense for a DLL. Using SSE* is dangerous with our GCC (not assembly though) as AOUT doesn't properly support the .align directive. One workaround is -mstack-realign.
Thanks