0

Generally speaking, I'm trying to compile a CPP library into my own library as a DLL for Android (or, more accurately, an .so file). When my toolkit (more on this later) runs the following lines:

arm-linux-androideabi-g++ -Iinclude/common -Iinclude/android -std=gnu++11 --sysroot=c:\android\ndk/platforms/android-19/arch-arm -Ic:\android\ndk/sources/cxx-stl/gnu-libstdc++/4.6/include -Ic:\android\ndk/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=0 -IC:/HaxeToolkit/haxe/lib/hxcpp/3,1,39/include -Iinclude -fpic -fvisibility=hidden -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums "-D_LINUX_STDDEF_H " -Wno -psabi -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -fomit-frame-pointer -fexceptions -fno-strict-aliasing -finline-limit=10000 -DANDROID=ANDROID -Wa,--noexecstack -O2 -DNDEBUG -c -x c++ -frtti ./common/ExternalInterface.cpp -oobj/android-v7/802265c0_ExternalInterface.obj
arm-linux-androideabi-g++ -o../ndll/Android/libopenflgpg-v7.so -frtti -nostdlib -Wl,-shared,-Bsymbolic -Wl,--no-undefined -Wl,-z,noexecstack --sysroot=c:\android\ndk/platforms/android-19/arch-arm -Lc:\android\ndk/platforms/android-19/arch-arm/usr/lib @obj/android-v7/all_objs libs/android/libgpg-v7.a c:\android\ndk/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libgnustl_static.a c:\android\ndk/platforms/android-19/arch-arm/usr/lib/crtbegin_so.o c:\android\ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.6/libgcc.a c:\android\ndk/platforms/android-19/arch-arm/usr/lib/libc.so c:\android\ndk/platforms/android-19/arch-arm/usr/lib/libm.so -llog -ldl

I get this error (and a ton more just like it):

gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: libs/android/libgpg-v7.a: in function gpg::OperationQueue::Impl::StartThreadIfNotRunningLocked():turn_based_match_impl.pb.cc(.text._ZN3gpg14OperationQueue4Impl29StartThreadIfNotRunningLockedEv+0x94): error: undefined reference to 'std::__1::thread::~thread()'

It seems it can't find the std library; why not? I'm on Windows, with Microsoft Visual Studio C++ 2010 Express installed, if that helps.

More specifically, I'm trying to enable the Google Play Games C++ SDK in Haxe, by using HXCPP to compile an NDLL with all of the functions I'll be able to call using Lib.load in my Haxe code. The full project is here.

I've tried including typeinfo and about a dozen other headers to no avail. I admit that C++ is not my strong suit, so I could be overlooking something totally obvious. Thanks for your help!

steve richey
  • 497
  • 3
  • 16
  • I may be completly wrong, but in std::__1::thread, the __1 remind me of errors when linking my clang++ compiled code with a g++ compiled library (boost). So maybe one of your linked libraries is expecting a thread from another std lib (e.g. libc++) than libstdc++ – Bérenger Jul 29 '14 at 16:07
  • Okay, but how do I fix that? Or at least, test a different std lib. – steve richey Jul 29 '14 at 16:22
  • I don't know exactly. One way would be to re-compile all your external lib with the same flags, but I guess it isn't very satisfying. Besides, are you sure the gcc implementation of std has std::thread available for android ? – Bérenger Jul 29 '14 at 16:29
  • Also, if you can, try to compile with clang++ – Bérenger Jul 29 '14 at 16:31
  • Well I can't recompile the Google Play library because it's not open source, otherwise I would. AFAIK the only way to compile for Android via HXCPP is with `arm-linux-androideabi-g++`, but I guess I'm not sure what std lib is being used. Again, I'm not very great at C++. – steve richey Jul 29 '14 at 16:35
  • It looks like the std lib is coming by way of `Ic:\android\ndk/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include` but there's also `-nostdlib` which seems like it might be the cause of the problem. – steve richey Jul 29 '14 at 16:39
  • These topics should answer your question http://stackoverflow.com/questions/11730111/how-to-use-c0x-thread-in-android-ndk and http://stackoverflow.com/questions/15269496/how-to-compile-c11-code-with-android-ndk-and-eclipse – Bérenger Jul 29 '14 at 16:39

1 Answers1

0

Add this to your Application.mk file:

NDK_TOOLCHAIN_VERSION := clang
Bram
  • 7,440
  • 3
  • 52
  • 94