using pre-built static libraries for Android NDK development

I am trying to build an android application that uses static libraries from some existing c++ code. However I cannot seem to get things building, here are the steps I have taken so far..

I have ndk-r5b and have built the standalone toolchain as per ndk/docs/STANDALINE-TOOLCHAIN.html. I have then used the standalone toolchain compiler (arm-linux-androideabi-g++) instead of g++ for the CXX flag in the Makefile that compiles the static libraries I need. This compiles without errors and there are 3 static libraries produced. Here is a code snippet of some of the flags used to build the prebuilt libraries:

CXX = arm-linux-androideabi-g++
SYSTEM_LIBS = -lstdc++ -lm
INCLUDE_PATH += ${NDK_PATH}/platforms/android-8/arch-arm/usr/include/

Here is a sample line that is produced from the makefile when compiling:

arm-linux-androideabi-g++ -c -DTIME_SIM -I./include  -I/home/greg/dev/Android/android-ndk-r5b/platforms/android-8/arch-arm/usr/include/ -fpic -ggdb3 -SimTime.C -o SimTime.o

Next I build the app using ndk-build using the following for

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := engine
LOCAL_SRC_FILES := ../libs/libEngine.a

include $(CLEAR_VARS)
LOCAL_SRC_FILES := ../libs/libShMem.a

include $(CLEAR_VARS)
LOCAL_SRC_FILES := ../libs/libUtil.a

# build server as a shared library
include $(CLEAR_VARS)
LOCAL_MODULE := libServer   
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include 

    Server.C \
    Router.C \
    RouterMsgs.C \
    Federation.C \
    cripName.C \
    ver.C \
LOCAL_STATIC_LIBRARIES := engine shmem util

The prebuilt libraries compile fine using the standalone toolchain compiler given in the android ndk. However there are many unresolved references to ostream when linking the shared library to the prebuilt libraries using ndk-build. For exampe:

/home/android/obj/local/armeabi/libShMem.a(SubscriptionItem.o): In function `SUBSCRIPTION_ITEM::Print(std::basic_ostream<char, std::char_traits<char> >&)':/home/src/comm/SubscriptionItem.C:97: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'

I assume I am missing some important flags or not doing something correct when I am compiling using the standalone compiler but any help or insight on this issue would be greatly appreciated as I cant seem to find this answer on google or in any of the android ndk docs. Thanks!


Well, you can actually fix that with creating a file inside the same folder as the file is, containing:

APP_STL := stlport_static

for using the static stlport that is located inside the Android NDK.

I had the same issue and resolved it by adding a module for the standard C++ library. The library linked by the ndk-build system is from the wrong location (platforms/android-9/arch-arm/usr/lib in my case).

include $(CLEAR_VARS)
LOCAL_MODULE := rightstdc
LOCAL_SRC_FILES := <path to the correct libstdc++.a>

Add the module tag to the list of static libraries:

LOCAL_STATIC_LIBRARIES := engine shmem util rightstdc

The build/core/ prepends -L$(SYSROOT)/usr/lib if any libraries are specified in LOCAL_LDLIBS but in my case that is the wrong path.

I don't know if there is a missing step that should copy the correct libstdc++ to that location but the approach above will work.

Need Your Help

Regex to determine if the value is valid in JS returns null

javascript regex

I want to check if a value is a valid pair of digits, having a dot and has zero, one or two digits behind the dot.

Scroll with easing

jquery scroll mousewheel easing

I have spent a lot of time to finding a jquery code that ensures that I can scroll with an easing effect.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.