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 4862

Summary: Undefined reference to hid_* symbols when building with CMake for Android
Product: SDL Reporter: David Demelier <demelier.david>
Component: buildAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: blocker    
Priority: P2 CC: sylvain.becker
Version: 2.0.10   
Hardware: ARM   
OS: Android (All)   
Attachments: build.txt

Description David Demelier 2019-11-14 11:43:59 UTC
Created attachment 4047 [details]
build.txt

I have a few undefined references when trying to build for Android using the following variables:

cmake .. \
	-DBUILD_SHARED_LIBS=On \
	-DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_TOOLCHAIN_FILE=/home/markand/android/ndk/20.0.5594570/build/cmake/android.toolchain.cmake \
	-DCMAKE_FIND_ROOT_PATH=/home/markand/android/env/armeabi-v7a-24 \
	-DANDROID_ABI=armeabi-v7a \
	-DANDROID_PLATFORM=24 \
	-DANDROID_STL=c++_shared \
	-DCMAKE_INSTALL_PREFIX=/home/markand/android/env/armeabi-v7a-24 \

I attach the complete error log, otherwise here's the snippet at the build failure:

[ 97%] Linking C shared library libSDL2.so
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_ps4.c:241: error: undefined reference to 'hid_get_feature_report'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_ps4.c:389: error: undefined reference to 'hid_write'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_ps4.c:518: error: undefined reference to 'hid_read_timeout'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_switch.c:235: error: undefined reference to 'hid_write'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_switch.c:230: error: undefined reference to 'hid_read_timeout'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xbox360.c:277: error: undefined reference to 'hid_write'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xbox360.c:372: error: undefined reference to 'hid_write'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xbox360.c:718: error: undefined reference to 'hid_read_timeout'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapi_xboxone.c:276: error: undefined reference to 'hid_read_timeout'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:872: error: undefined reference to 'hid_enumerate'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:882: error: undefined reference to 'hid_free_enumeration'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:690: error: undefined reference to 'hid_init'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:967: error: undefined reference to 'hid_open_path'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:975: error: undefined reference to 'hid_close'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:1026: error: undefined reference to 'hid_close'
/home/markand/android/src/SDL2-2.0.10/src/joystick/hidapi/SDL_hidapijoystick.c:1050: error: undefined reference to 'hid_exit'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/SDL2.dir/build.make:2129: libSDL2.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:79: CMakeFiles/SDL2.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
Comment 1 Sylvain 2019-11-14 19:41:16 UTC
Do you use the latest head SDL sources ?

See this issue for some history: bug 3918

On Android CMake can also be used through Gradle, maybe this is the preferred way ...
SDL2 must be linked with its HID library.
Comment 2 David Demelier 2019-11-25 08:39:57 UTC
Sorry I've only tested the release version 2.0.10 not the development one.

So I should install the hidapi library (from https://github.com/signal11/hidapi)? It looks like it's no longer maintained though...
Comment 3 Sylvain 2019-11-25 10:53:03 UTC
No external lib, HID source code is within the SDL source tree.
Please try the latest dev version !