NDK r5 and gnustl_static

449 views
Skip to first unread message

John Sheehy

unread,
Dec 14, 2010, 8:24:40 PM12/14/10
to android-ndk
Hi all,

I'm having a bit of trouble trying to use the libstdc++ STL impl with
the latest NDK. I have a very simple test program that shows this. It
works fine with stlport_static, but I'm going to need RTTI and
exception support (even if I don't turn on exceptions or rtti in the
Application.mk, it still fails). Here are the linker errors:

/home/john/proj/obj/local/armeabi/objs-debug/System_jni/System_jni.o:
In function `std::vector<int, std::allocator<int>
>::_M_check_len(unsigned int, char const*) const':
/home/john/third_party/android-ndk-r5/sources/cxx-stl/gnu-libstdc++/
include/bits/stl_vector.h:1153: undefined reference to
`std::__throw_length_error(char const*)'

/home/john/proj/obj/local/armeabi/objs-debug/System_jni/System_jni.o:
In function `__gnu_cxx::new_allocator<int>::allocate(unsigned int,
void const*)':
/home/john/third_party/android-ndk-r5/sources/cxx-stl/gnu-libstdc++/
include/ext/new_allocator.h:87: undefined reference to
`std::__throw_bad_alloc()'

collect2: ld returned 1 exit status
make: *** [/home/john/proj/obj/local/armeabi/libSystem_jni.so] Error 1

Here's the very simple source file:

#include <vector>
#include "com_john_proj_System.h"

/*
* Class: com_john_proj_System
* Method: boot
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_john_proj_1System_boot
(JNIEnv *, jobject) {
std::vector<int> v;
v.push_back(10);
}


My Application.mk:

APP_OPTIM := debug
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -frtti
APP_STL := gnustl_static

and finally, my Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := System_jni
LOCAL_SRC_FILES := System_jni.cpp
LOCAL_ARM_MODE := arm
include $(BUILD_SHARED_LIBRARY)

Any ideas why I'm getting the link error with such a simple
experiment? Any help greatly appreciated.

John












Justin Holewinski

unread,
Dec 15, 2010, 7:18:12 AM12/15/10
to andro...@googlegroups.com
On Tue, Dec 14, 2010 at 8:24 PM, John Sheehy <she...@gmail.com> wrote:
Hi all,

I'm having a bit of trouble trying to use the libstdc++ STL impl with
the latest NDK. I have a very simple test program that shows this. It
works fine with stlport_static, but I'm going to need RTTI and
exception support (even if I don't turn on exceptions or rtti in the
Application.mk, it still fails). Here are the linker errors:

Are you cleaning out all of your build artifacts after changing from stlport_static to gnustl_static?  I've had issues in the past where changing the STL flag in Application.mk did not cause a proper rebuild so the linker was pulling in object files compiled against one STL implementation and the STL implementation library from another STL implementation.  Since the link errors involve exception handling, I'm inclined to believe this to be the case for you as well.

Make sure you run "ndk-build clean" and manually delete your libs/ and obj/ directories.
 












--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--

Thanks,

Justin Holewinski

John Sheehy

unread,
Dec 15, 2010, 3:00:37 PM12/15/10
to android-ndk
That was it indeed! Thanks a million.

On Dec 15, 4:18 am, Justin Holewinski <justin.holewin...@gmail.com>
wrote:
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .

David Turner

unread,
Dec 15, 2010, 4:06:28 PM12/15/10
to andro...@googlegroups.com
On Wed, Dec 15, 2010 at 1:18 PM, Justin Holewinski <justin.h...@gmail.com> wrote:
On Tue, Dec 14, 2010 at 8:24 PM, John Sheehy <she...@gmail.com> wrote:
Hi all,

I'm having a bit of trouble trying to use the libstdc++ STL impl with
the latest NDK. I have a very simple test program that shows this. It
works fine with stlport_static, but I'm going to need RTTI and
exception support (even if I don't turn on exceptions or rtti in the
Application.mk, it still fails). Here are the linker errors:

Are you cleaning out all of your build artifacts after changing from stlport_static to gnustl_static?  I've had issues in the past where changing the STL flag in Application.mk did not cause a proper rebuild so the linker was pulling in object files compiled against one STL implementation and the STL implementation library from another STL implementation.  Since the link errors involve exception handling, I'm inclined to believe this to be the case for you as well.

Ah, that's interesting, do you have a simple way to reproduce this problem, I'd like to add a fix for this to the build system.

Justin Holewinski

unread,
Dec 15, 2010, 5:26:20 PM12/15/10
to andro...@googlegroups.com
On Wed, Dec 15, 2010 at 4:06 PM, David Turner <di...@android.com> wrote:


On Wed, Dec 15, 2010 at 1:18 PM, Justin Holewinski <justin.h...@gmail.com> wrote:
On Tue, Dec 14, 2010 at 8:24 PM, John Sheehy <she...@gmail.com> wrote:
Hi all,

I'm having a bit of trouble trying to use the libstdc++ STL impl with
the latest NDK. I have a very simple test program that shows this. It
works fine with stlport_static, but I'm going to need RTTI and
exception support (even if I don't turn on exceptions or rtti in the
Application.mk, it still fails). Here are the linker errors:

Are you cleaning out all of your build artifacts after changing from stlport_static to gnustl_static?  I've had issues in the past where changing the STL flag in Application.mk did not cause a proper rebuild so the linker was pulling in object files compiled against one STL implementation and the STL implementation library from another STL implementation.  Since the link errors involve exception handling, I'm inclined to believe this to be the case for you as well.

Ah, that's interesting, do you have a simple way to reproduce this problem, I'd like to add a fix for this to the build system.

Sure, reproduction is fairly easy.

  1. Create a project with a single C++ source file that includes <iostream>, e.g.
    #include <iostream>

    int foo() { return 42; }

  2. Set APP_STL to stlport_static in Application.mk
  3. Build the project with ndk-build (need a successful build here)
  4. Set APP_STL to gnustl_static in Application.mk
  5. Build the project
  6. Observe the error
The test I just ran gave me the following error:

Compile++ thumb  : test <= MyFile.cpp
SharedLibrary  : libtest.so
/Users/jholewinski/android/sandbox/stltest/obj/local/armeabi/objs/test/MyFile.o: In function `__static_initialization_and_destruction_0':
/Users/jholewinski/android/android-ndk-r5/sources/cxx-stl/gnu-libstdc++/include/iostream:72: undefined reference to `std::ios_base::Init::Init()'
/Users/jholewinski/android/sandbox/stltest/obj/local/armeabi/objs/test/MyFile.o: In function `global constructors keyed to MyFile.cpp':
/Users/jholewinski/android/sandbox/stltest/jni/MyFile.cpp:9: undefined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status
make: *** [/Users/jholewinski/android/sandbox/stltest/obj/local/armeabi/libtest.so] Error 1


As far as I can tell, the iostream header requires a global static symbol (std::ios_base::Init::Init()) that for some reason cannot be resolved when switching STL implementations, implying some leftover intermediate files somewhere.



--

Thanks,

Justin Holewinski

Reply all
Reply to author
Forward
0 new messages