简体   繁体   中英

How to link multiple static libs in android shared lib

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, ie:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM