{"id":3378,"date":"2014-03-23T13:50:03","date_gmt":"2014-03-23T13:50:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/23\/using-pre-built-static-libraries-for-android-ndk-development-collection-of-common-programming-errors-2\/"},"modified":"2014-03-23T13:50:03","modified_gmt":"2014-03-23T13:50:03","slug":"using-pre-built-static-libraries-for-android-ndk-development-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/23\/using-pre-built-static-libraries-for-android-ndk-development-collection-of-common-programming-errors-2\/","title":{"rendered":"using pre-built static libraries for Android NDK development-Collection of common programming errors"},"content":{"rendered":"<p>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..<\/p>\n<p>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:<\/p>\n<pre><code>CXX = arm-linux-androideabi-g++\nSYSTEM_LIBS = -lstdc++ -lm\nINCLUDE_PATH += ${NDK_PATH}\/platforms\/android-8\/arch-arm\/usr\/include\/\n<\/code><\/pre>\n<p>Here is a sample line that is produced from the makefile when compiling:<\/p>\n<pre><code>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\n<\/code><\/pre>\n<p>Next I build the app using ndk-build using the following for Android.mk:<\/p>\n<pre><code>LOCAL_PATH := $(call my-dir)\n\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := engine\nLOCAL_SRC_FILES := ..\/libs\/libEngine.a\ninclude $(PREBUILT_STATIC_LIBRARY)\n\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := shmem\nLOCAL_SRC_FILES := ..\/libs\/libShMem.a\ninclude $(PREBUILT_STATIC_LIBRARY)\n\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := util\nLOCAL_SRC_FILES := ..\/libs\/libUtil.a\ninclude $(PREBUILT_STATIC_LIBRARY)\n\n# build server as a shared library\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := libServer   \nLOCAL_C_INCLUDES := $(LOCAL_PATH)\/..\/..\/include \n\nLOCAL_SRC_FILES := \\\n    Server.C \\\n    Router.C \\\n    RouterMsgs.C \\\n    Federation.C \\\n    cripName.C \\\n    ver.C \\\n    JNIWrapper.cpp\nLOCAL_STATIC_LIBRARIES := engine shmem util\ninclude $(BUILD_SHARED_LIBRARY)\n<\/code><\/pre>\n<p>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:<\/p>\n<pre><code>\/home\/android\/obj\/local\/armeabi\/libShMem.a(SubscriptionItem.o): In function `SUBSCRIPTION_ITEM::Print(std::basic_ostream&amp;)':\/home\/src\/comm\/SubscriptionItem.C:97: undefined reference to `std::basic_ostream&amp; std::operator<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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++) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3378","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3378"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3378\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}