Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Android] Using c++11 and gnustl  (Read 5480 times)

0 Members and 1 Guest are viewing this topic.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
[Android] Using c++11 and gnustl
« on: July 22, 2016, 12:37:14 pm »
The code that I have requires c++11 and always worked without issues because libc++ could be used (and was used by default by SFML).
The last sfml commit however removed support for c++_shared and c++_static. (Could someone perhaps link to a discussion on why libc++ support was dropped?)

I can't use stlport because it lacks c++11 support (it e.g. does not have std::shared_ptr).

My code could compile using gnustl with minor modifications (gnustl e.g. misses std::round), but SFML seems to crash when using this STL. Below is the adb logcat output of the crash when running the sfml android example with "APP_STL := gnustl_static" and "APP_ABI := x86" set in jni/Application.mk.
Code: [Select]
07-22 11:32:13.163  2998  3011 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0xc730245c in tid 3011 (om.example.sfml)
07-22 11:32:13.280   950   950 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-22 11:32:13.280   950   950 F DEBUG   : Build fingerprint: 'Android/sdk_google_phone_x86/generic_x86:6.0/MASTER/2524533:userdebug/test-keys'
07-22 11:32:13.280   950   950 F DEBUG   : Revision: '0'
07-22 11:32:13.280   950   950 F DEBUG   : ABI: 'x86'
07-22 11:32:13.280   950   950 F DEBUG   : pid: 2998, tid: 3011, name: om.example.sfml  >>> com.example.sfml <<<
07-22 11:32:13.280   950   950 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xc730245c
07-22 11:32:13.283   950   950 F DEBUG   :     eax c730245c  ebx b734a71c  ecx c730245c  edx b7357f1c
07-22 11:32:13.283   950   950 F DEBUG   :     esi c7302454  edi ab200000
07-22 11:32:13.283   950   950 F DEBUG   :     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000007  xss 0000007b
07-22 11:32:13.283   950   950 F DEBUG   :     eip b72d3ba3  ebp ab2381f0  esp a40ff210  flags 00210286
07-22 11:32:13.285   950   950 F DEBUG   :
07-22 11:32:13.285   950   950 F DEBUG   : backtrace:
07-22 11:32:13.285   950   950 F DEBUG   :     #00 pc 00081ba3  /system/lib/libc.so (pthread_mutex_lock+11)
07-22 11:32:13.285   950   950 F DEBUG   :     #01 pc 000a281a  /system/lib/libc.so (je_arena_dalloc_large+40)
07-22 11:32:13.285   950   950 F DEBUG   :     #02 pc 000be74e  /system/lib/libc.so (je_free+830)
07-22 11:32:13.285   950   950 F DEBUG   :     #03 pc 00016c4b  /system/lib/libc.so (free+30)
07-22 11:32:13.285   950   950 F DEBUG   :     #04 pc 00009e6b  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (operator delete(void*)+27)
07-22 11:32:13.285   950   950 F DEBUG   :     #05 pc 000081f6  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (main+1494)
07-22 11:32:13.285   950   950 F DEBUG   :     #06 pc 000082d8  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (sf::priv::main(sf::priv::ActivityStates*)+152)
07-22 11:32:13.285   950   950 F DEBUG   :     #07 pc 000089b0  /data/app/com.example.sfml-1/lib/x86/libsfml-example.so (sf::priv::ThreadFunctorWithArg<void* (*)(sf::priv::ActivityStates*), sf::priv::ActivityStates*>::run()+16)
07-22 11:32:13.285   950   950 F DEBUG   :     #08 pc 0000e082  /data/app/com.example.sfml-1/lib/x86/libsfml-system.so (sf::Thread::run()+18)
07-22 11:32:13.285   950   950 F DEBUG   :     #09 pc 0000f24b  /data/app/com.example.sfml-1/lib/x86/libsfml-system.so
07-22 11:32:13.285   950   950 F DEBUG   :     #10 pc 00080a93  /system/lib/libc.so (__pthread_start(void*)+56)
07-22 11:32:13.285   950   950 F DEBUG   :     #11 pc 00021952  /system/lib/libc.so (__start_thread+25)
07-22 11:32:13.285   950   950 F DEBUG   :     #12 pc 000170b6  /system/lib/libc.so (__bionic_clone+70)

This was the cmake command used for this sfml version:
Code: [Select]
cmake -DANDROID_ABI=x86 -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/android.toolchain.cmake -DANDROID_STL=gnustl_static ..
The same crash seems to occur in older SFML versions as well, but at least in these version I was able to use c++_static (or c++_shared).

Is there a way to use c++11 on android with the latest sfml version?
« Last Edit: July 22, 2016, 12:39:19 pm by texus »
TGUI: C++ SFML GUI

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [Android] Using c++11 and gnustl
« Reply #1 on: July 22, 2016, 02:06:33 pm »
I'm also concerned by this change in SFML as my app uses C++11 features.

EDIT : It seems that the android-cmake project (used by SFML) has dropped support for libc++...

EDIT2 : I've tested myself with gnustl_shared, it crashes (SIGABRT) on sf::String::~String
« Last Edit: July 22, 2016, 03:05:37 pm by victorlevasseur »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: [Android] Using c++11 and gnustl
« Reply #2 on: July 23, 2016, 12:37:39 pm »
Hmpf, have to check that. Updated my NDK and the toolchain file and c++_shared/c++_static weren't there anymore, so I just picked a different default. Have to check that.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: [Android] Using c++11 and gnustl
« Reply #3 on: July 23, 2016, 01:02:10 pm »
Okay, seems like libc++ just wasn't supported in the toolchain file by default. I've added it once again and created a new branch.

Would be great if you could test the branch "bugfix/android-libc++" and leave your feedback in the associated pull request on GitHub.

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [Android] Using c++11 and gnustl
« Reply #4 on: July 23, 2016, 01:03:46 pm »
Thank you for your quick reaction.  :D I'll test it soon.

 

anything