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 3675

Summary: Android builds fail due to -lpthread
Product: SDL Reporter: Anthony Pesch <inolen>
Component: buildAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus, ivan.perez
Version: HG 2.1Keywords: target-2.0.6
Hardware: x86_64   
OS: Linux   
Attachments: Avoid appending -lpthread to SDL_LIBS for Android

Description Anthony Pesch 2017-06-20 01:48:42 UTC
Created attachment 2765 [details]
Avoid appending -lpthread to SDL_LIBS for Android

Android builds fail for me with:

/opt/android-ndk-r15/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lpthread
collect2: error: ld returned 1 exit status


From googling, it appears that Android's libc has pthread support builtin, and doesn't supply an actual pthread library to link to.

I've attached a patch which doesn't append -lpthread to SDL_LIBS when building for Android.
Comment 1 Ivan (Keera Studios) 2017-06-20 22:23:21 UTC
I'm using SDL for Android (and iOS) and so far I haven't had to change anything to compile it.

Does this problem also happen with other NDKs?
Comment 2 Anthony Pesch 2017-06-24 20:10:05 UTC
Ivan, the issue could be many things:

a.) some difference in NDKs (however, it seems this has been the case since ndk r8 https://github.com/morningtec/android-ndk-r8d/blob/master/docs/system/libc/OVERVIEW.html#L102)

b.) you're not compiling SDL as a static library (which is what would use the SDL_LIBS variable)

c.) you are compiling SDL as a static library, but not actually relying on CMake's higher-level targets to link the library, thus SDL_LIBS is not used

so on and so forth.
Comment 3 Ryan C. Gordon 2017-08-09 05:25:35 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.6.

This means we're in the final stretch for an official SDL 2.0.6 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.6 release, and generally be organized about what we're aiming to ship. After some debate, we might just remove this tag again and deal with it for a later release.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.
Comment 4 Ryan C. Gordon 2017-08-09 23:51:12 UTC
 
> c.) you are compiling SDL as a static library, but not actually relying on
> CMake's higher-level targets to link the library, thus SDL_LIBS is not used

d.) most people aren't using the CMake projects on Android (...yet!).

This patch is now https://hg.libsdl.org/SDL/rev/3d59240ebfd9, thanks!


--ryan.