How to link multiple static libs in android shared lib - android

I have pre build boost libs for android using standalone tool chain 4.8.
I want to use he following boost libs and added as following in Android.mk
LOCAL_STATIC_LIBRARIES += libboost_atomic \
libboost_date_time \
libboost_exception \
libboost_thread \
libboost_system \
libboost_filesystem
I have adde my own static lib liblocal.a in Android.mk.
I have a mainactivity.cpp file in my JNI folder of android project.
I am including header.h in mainactivity.h. header.h had class declaration for classA which uses boost libs.
while building liblocal.a, I am not getting any link error for boost.
While inclduding header.h in mainactivity.h I am getting the following link error:
../../../3p/boost/android/include/boost/system/error_code.hpp:222: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:223: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:224: error: undefined reference to 'boost::system::system_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:222: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:223: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:224: error: undefined reference to 'boost::system::system_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:224: error: undefined reference to 'boost::system::system_category()'
Thanks,
Birajendu

If liblocal.a depends on functions defined in libboost_foo.a, then it must appear before it in the list of static libraries, i.e.:
LOCAL_STATIC_LIBRARIES += liblocal.a libboost_foo.a # GOOD
Should work, while the following:
LOCAL_STATIC_LIBRARIES += libboost_foo.a liblocal.a # BAD
will not, and result in a link error like the one you described.
A work-around is to use LOCAL_WHOLE_STATIC_LIBRARIES that always forces all content from the listed static libraries to be included in the result (this typically generates bloated binaries, but may be necessary if you have circular dependencies).
Hope this helps.

Solved:
I have added LOCAL_LDLIBS += -L$(RELATIVE_PATH_TO_LIB) -lmylib -lmylib1, this solved this issue.
Where as mylib.a and mylib1.a are my pre build static libs.

Related

Qt: Undefined reference to atof, log2 & log2f on android linking to FFmpeg

Trying to build my Qt application for android linking to FFmpeg.
I get the following linker errors on android.
libavformat/hls.c:783: error: undefined reference to 'atof'
libavcodec/ffv1enc.c:476: error: undefined reference to 'log2'
libavcodec/imc.c:472: error: undefined reference to 'log2f'
Following is the list of libraries I trying to link for FFmpeg.
-lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice -lpostproc -lm -lgnustl_static
What am I missing in the linker options?
I have also set the following to :
CONFIG += c++14
QMAKE_CXXFLAGS_RELEASE += -std=c++1y
QMAKE_CXXFLAGS_DEBUG += -std=c++1y
This is strictly not related to Qt and happens only because those functions are not defined in Android, as discussed in Does Android support log2 and Android ndk can't find atof function, among other places.
You either have to define those functions before including FFmpeg headers or find a library that does this for you.

Android: error: undefined reference to 'android_atomic_dec'

I am trying to build my code for h.264 video decoding using hardware decoder(OMX codec) in native code of android 4.0.4 by keeping it in the android source tree. The android source is already built. I am using mm command to build my decoder module.
But when I try to build it I am getting the following error
prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld:
out/target/product/generic/obj/SHARED_LIBRARIES/custom_decoder_intermediates/custom_decoder.o:
in function custom_decoder::decode_video():frameworks/base/include/utils/RefBase.h:171:
error: undefined reference to 'android_atomic_dec'
when I explored about it, came to know that android_atomic_dec is defined in cutils/atomic.h
which is in system/core/libcutils and the header at system/core/include/cutils of AOSP 4.0.4.
So I have added this also in my android.mk via LOCAL_C_INCLUDES but still to get the same error.
Can someone help me to solve this ??....
You must add cutils to the linkage stage:
LOCAL_LDLIBS += -L $(path-to-system-libs) -lcutils
If you are building AOSP tree, use instead the following:
LOCAL_SHARED_LIBRARIES += libcutils

C++ on Android missing std::map:at

I am trying to compile my cocos2d-x project for android, but it I get the error:
jni/../../Classes/Utility.cpp:359:47: error: 'class
std::map,
std::allocator >, std::basic_string, std::allocator > >' has no member named
'at' make: *
[obj/local/armeabi/objs-debug/game_shared///Classes/Utility.o]
Error 1
I have set APP_STL := stlport_static in Application.mk (not Android.mk), I even have set the eclipse include path {android-ndk-r9}/sources/cxx-stl/stlport/stlport. But still nothing, any ideas? or is that method just not included in this version of c++?
UPDATE
I am using stlport_static, which is defined as follows (as static library):
I.3. STLport runtime:
This is a port of STLport (http://www.stlport.org) that can be used on
Android. It will provide you with a complete set of C++ standard
library headers, with RTTI and exception handling support.
That's because the library embeds its own copy of GAbi++.
My cocos2d-x version is 2.1rc0-x-2.1.4

Android - error: undefined reference to 'vtable for __cxxabiv1::__si_class_type_info'

Ok, I give up...
I've been trying to compile android's 4.x (x>=1) webkit to bypass the 4.0 bugs.
After a few compilations, of the libwebcore with correct bindings and different namespace, and android.webkit with different namespace and some code fixes to match 4.0 - it compiles, and works, on Android 4.3.
Additional problems came in when trying to run it on 4.0-4.2 - where I found out the libicuuc is incompatible between versions, as versioning occurs in the function names. So the solution is theoretically simple - compile libicuuc statically into the libwebcore, by adding LOCAL_STATIC_LIBRARIES += libicuuc to the Android.mk
This is where hell began: I get errors like error: undefined reference to 'vtable for __cxxabiv1::__si_class_type_info' and error: undefined reference to '__dynamic_cast'.
I tried adding LOCAL_RTTI_FLAG := -frtti but it didn't change anything.
Any ideas?
Thanks!

Linker errors in Android NDK (undefined reference to `__cxa_end_cleanup')

I'm getting this output after adding in a set of code from a colleague:
./obj/local/armeabi/objs/jniWrapper/native.o: In function `_Vector_base':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_vector.h:73: undefined reference to `__cxa_end_cleanup'
./obj/local/armeabi/objs/jniWrapper/native.o:(.ARM.extab.text._ZNSt6vectorIhSaIhEEC1ERKS1_[std::vector<unsigned char, std::allocator<unsigned char> >::vector(std::vector<unsigned char, std::allocator<unsigned char> > const&)]+0x0): undefined reference to `__gxx_personality_v0'
./obj/local/armeabi/objs/jniWrapper/native.o: In function `std::__node_alloc::deallocate(void*, unsigned int)':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_alloc.h:161: undefined reference to `__cxa_end_cleanup'
./obj/local/armeabi/objs/jniWrapper/native.o:(.ARM.extab.text._ZNSt4priv12_String_baseIcSaIcEED2Ev[std::priv::_String_base<char, std::allocator<char> >::~_String_base()]+0x0): undefined reference to `__gxx_personality_v0'
./obj/local/armeabi/objs/jniWrapper/native.o: In function `basic_string':
D:/opt/android-ndk/sources/cxx-stl/stlport/stlport/stl/_string.c:643: undefined reference to `__cxa_end_cleanup'
This is caused because I don't have access to the correct STL.
To my knowledge there are only three I can choose from (stlport_static, stlport_shared, system) as set by APP_STL := stlport_static in Application.mk.
Is there another library available to the NDK?
After reading android-ndk/docs/CPLUSPLUS-SUPPORT.html I found that there a couple more libraries that I can link to:
C++ C++ Standard
Exceptions RTTI Library
system no no no
gabi++ no yes no
stlport no yes yes
gnustl yes yes yes
This stops my linker errors (and pushes the build onto a new set of errors :))
Application.mk
APP_STL := gnustl_static
Take a look here: Linux C++: Linker is outputting strange errors.
In Android's Application.mk this would be:
APP_CPPFLAGS := -frtti
You can fix this problem by adding the compiler option -lsupc++.
Edited:
The reason: your code is using C++ exception mechanism which compiler automatically generate try/catch/finally block hidden code which in turn call __cxa_end_cleanup somewhere.
lsupc++ means link to libsupc++.a
Another way to resolve this problem is add -fno-exceptions option to gcc which obviously means disable exception handler mechanism.
BTW, you should also add -fno-rtti to avoid other maybe-encountered compilation error, this is because
all android's C++ class is compiled without dynamic type info in class memory layout.
In a word, you shoud use one of these option combos:
1. -fno-rtti -fno-exceptions
2. -fno-rtti -lsupc++
In my case, the error undefined reference to __cxa_end_cleanup shows up when I add -fexceptions to the compiler options. When removing that option, the undefined ref goes away, but that means you have to clear your code from exception statements.
for me that meant adding -fno-rrti and -fno-exceptions then getting rid of "throw char*" in the code which took care of both.

Categories

Resources