WARNING: ... / Android.mk: non-system libraries in linker flags

I get this warning while running $ANDROID_NDK_ROOT/ndk-build . Android.mk below.

 $ $ANDROID_NDK_ROOT/ndk-build WARNING:/Users/jwalton/Android-CryptoPP/jni/Android.mk:prng: non-system libraries in linker flags: -lcryptopp -lstlport_shared This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the current module ... 

However, when I follow the instructions and -lcryptopp -lstlport_shared from LOCAL_LDLIBS , I get link errors associated with characters from libstlport_shared.so . Below is an example of errors after the Android.mk file.

How, exactly, ndk-build you want Android.mk configure ndk-build ?

Why do I need to add $(STLPORT_INCL) to LOCAL_C_INCLUDES and $(STLPORT_LIB) to LOCAL_LDFLAGS ? Why did APP_STL := stlport_shared not configure STL correctly out of the box?


 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) TARGET_ARCH_ABI := armeabi TARGET_ABI := android-9-armeabi CRYPTOPP_INCL := /usr/local/cryptopp-android-9/include CRYPTOPP_LIB := /usr/local/cryptopp-android-9/lib STLPORT_INCL := /opt/android-ndk-r9/sources/cxx-stl/stlport/stlport STLPORT_LIB := /opt/android-ndk-r9/sources/cxx-stl/stlport/libs/armeabi APP_STL := stlport_shared APP_MODULES := stlport_shared cryptopp LOCAL_CPP_FEATURES := rtti exceptions LOCAL_C_INCLUDES := $(CRYPTOPP_INCL) $(CRYPTOPP_INCL)/cryptopp $(STLPORT_INCL) LOCAL_LDFLAGS := -L $(CRYPTOPP_LIB) -L $(STLPORT_LIB) LOCAL_LDLIBS := -lcryptopp -lstlport_shared -llog -landroid # LOCAL_LDLIBS := -llog -landroid # LOCAL_SHARED_LIBRARIES := -lcryptopp -lstlport_shared LOCAL_MODULE := prng LOCAL_SRC_FILES := libprng.cpp include $(BUILD_SHARED_LIBRARY) 

Here is an example error when trying to follow the advice by removing my local libraries from LOCAL_LDLIBS :

 $ $ANDROID_NDK_ROOT/ndk-build Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 9 in /Users/jwalton/Android-CryptoPP/AndroidManifest.xml Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver Gdbsetup : libs/armeabi/gdb.setup Compile++ thumb : prng <= libprng.cpp SharedLibrary : libprng.so /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/jwalton/Android-CryptoPP/obj/local/armeabi/objs-debug/prng/libprng.o: in function std::__node_alloc::allocate(unsigned int&):/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/stl/_alloc.h:158: error: undefined reference to 'std::__node_alloc::_M_allocate(unsigned int&)' /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/jwalton/Android-CryptoPP/obj/local/armeabi/objs-debug/prng/libprng.o: in function std::__node_alloc::deallocate(void*, unsigned int):/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/stl/_alloc.h:161: error: undefined reference to 'std::__node_alloc::_M_deallocate(void*, unsigned int)' /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/jwalton/Android-CryptoPP/obj/local/armeabi/objs-debug/prng/libprng.o: in function std::ios_base::_M_check_exception_mask():/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/stl/_ios_base.h:193: error: undefined reference to 'std::ios_base::_M_throw_failure()' 

...

+6
source share
1 answer

I interpret the message "non-system libraries in the linker flags" as a warning that you are not using the default system libraries (in usr/lib ), which can be completely accurate, but which can also lead to errors (incompatibility between versions of different libraries) . Does this warning mean that you are completely up to you.

Then, about how you tried to solve it, I think you mistakenly use the LOCAL_SHARED_LIBRARIES NDK variable.

Paste here a sample from one of my Android.mk files that uses Assimp

 #------------------------------------------------------------------ Assimp include $(CLEAR_VARS) LOCAL_MODULE := Assimp LOCAL_EXPORT_C_INCLUDES := $(GENERATED_INCLUDE_PATH)/assimp/include LOCAL_SRC_FILES := $(GENERATED_PATH)/assimp/lib/libassimp.a include $(PREBUILT_STATIC_LIBRARY) ... LOCAL_STATIC_LIBRARIES := \ Assimp \ <Your other libs here> 

As you can see, I declare LOCAL_MODULE with a custom name, configure several variables, and then include a PREBUILT_STATIC_LIBRARY script that tells the NDK to use this library.

Then, in LOCAL_STATIC_LIBRARIES I list the libraries that I use with their module name , but not as if it were a linker flag, as you do here.

In your case, I believe you should do the following, for example for stl

 include $(CLEAR_VARS) LOCAL_MODULE := STLPortShared LOCAL_EXPORT_C_INCLUDES := <path to stlport includes> LOCAL_SRC_FILES := <path to stlport library> include $(PREBUILT_SHARED_LIBRARY) ... #Notice the name, identical to the one specified for LOCAL_MODULE LOCAL_SHARED_LIBRARIES = STLPortShared 

I think this should do it. Of course, repeat the process for each libs that causes problems, and don't forget to include(CLEAR_VARS) between each lib specification.

+8
source

Source: https://habr.com/ru/post/955306/


All Articles