| Summary: | Android: nativeRunMain(): Couldn’t find function SDL_main in library | ||
|---|---|---|---|
| Product: | SDL | Reporter: | ZZ <registrirayme> |
| Component: | main | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | blocker | ||
| Priority: | P1 | CC: | sylvain.becker |
| Version: | 2.0.8 | ||
| Hardware: | ARM | ||
| OS: | Android (All) | ||
|
Description
ZZ
2018-09-26 06:20:23 UTC
Could this be the same at bug #4002 ? I would say no, because in that case this is the library which cannot be found. use objdump on your build libraries: objdump -T build/intermediates/ndkBuild/release/obj/local/arm64-v8a/libmain.so | grep main gives: 00000000000ca508 g DF .text 0000000000000128 Base SDL_main I don't think that the above bug is anything like this one. From what I've read is that SDL_main get's stripped as unused during linking.
My project has the following structure:
1. executable
2. engine library (dynamic)
3. sdl library (dynamic)
4. a static library that containts int main() (thus contains SDL_main)
In that configuration compiled with MSVC and Clang on Windows, and GCC on Linux it works. On Android on the other hand I get the above error message.
The workaround I found was to compile libraries 2 and 3 as static and to link them to the executable like that (I use CMake):
target_link_libraries (${PROJECT_NAME}
# Prevent SDL_main from being stripped when linked in a static library
$<$<PLATFORM_ID:Android>:-Wl,--whole-archive>
Engine_main
$<$<PLATFORM_ID:Android>:-Wl,--no-whole-archive>
)
I missed an important bit of information. I am using NDK r18 and the target arm64-v8a. While the above workaround helps it is not optimal because it limits flexibility. Yes, if you have a static library, you're only guaranteed to link in the functions that are actually referenced by your executable. One way to guarantee that you pull it in is to have a static function pointer in your executable that points to the function. |