We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4816 - Controller Subsystem Failing With Static Library
Summary: Controller Subsystem Failing With Static Library
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.9
Hardware: x86_64 Windows 10
: P2 major
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.16
Depends on:
Blocks:
 
Reported: 2019-10-07 06:26 UTC by Ryan Edward
Modified: 2020-07-16 18:29 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Edward 2019-10-07 06:26:49 UTC
I compile sdl2 as a static library like so:

cmake.exe -DCMAKE_BUILD_TYPE=Debug -G "MinGW Makefiles"^
 -DCMAKE_C_FLAGS="-target x86_64-windows-gnu" -DCMAKE_C_COMPILER="clang.exe" -DCMAKE_C_COMPILER_ID="Clang"^
 -DVIDEO_OPENGL=ON -DDIRECTX=OFF^
 -DSDL_STATIC=ON -DSDL_SHARED=OFF -DSDL_TEST=OFF ..
cmake.exe --build . -- -j %NUMBER_OF_PROCESSORS%

I link against this static library like so:

SET ll_common_flags=-DLL_SLOW -DLL_DEV -fno-omit-frame-pointer -fno-optimize-sibling-calls -g^
 -target x86_64-windows-gnu -fuse-ld=lld.exe -Wall -Wextra -Wpedantic -Wfloat-equal -Wunreachable-code -Wshadow^
 -Wno-gnu

clang.exe %ll_common_flags% ..\code\sdl-ll.c -o sdl-ll.exe^
 -Wl,-subsystem,windows -I ..\sdl2-2.0.9-minimal\include -L ..\sdl2-2.0.9-minimal\build^
  -lmingw32 -lwinmm -lole32 -limm32 -loleaut32 -lgdi32 -luuid -lversion -lopengl32^
    -lSDL2maind -lSDL2d 

This line fails:

if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC | SDL_INIT_AUDIO) < 0) {
    SDL_LogCritical("Unable to initialize SDL: %s", SDL_GetError());
    return EXIT_FAILURE;
  }

When I run under a debugger ‘SDL_GetError()’ does not return anything meaningful (actually nothing at all). The video and audio subsystems work fine when initialized together. It is the gamecontroller and haptic that cause it to fail. Suggestions?

EDIT:
I have tried compiling with microsoft libraries, i.e. cl.exe and associated headers:

cmake.exe -DCMAKE_BUILD_TYPE=Debug^
  -DVIDEO_OPENGL=ON -DDIRECTX=OFF -DRENDER_D3D=OFF -DVIDEO_DUMMY=OFF -DVIDEO_OPENGLES=OFF -DVIDEO_VULKAN=OFF^
  -DDISKAUDIO=OFF -DDUMMYAUDIO=OFF^
  -DSDL_STATIC=ON -DSDL_SHARED=OFF -DSDL_TEST=OFF ..
cmake.exe --build . 

I get a syntax error in SDL_joystick.c.

Subsequently I cannot build sdl2, only sdl2-main.

It seems that cl.exe does not support the C99 initialization here. So if this is the case, how has anyone compiled sdl2.0.9 for windows with working controller support??