警告:... / Android.mk:链接器标志中的非系统库

时间:2014-09-04 11:10:11

标签: android c++ android-ndk ndk-build

我在运行$ANDROID_NDK_ROOT/ndk-build时收到此警告。 Android.mk位于下方。

$ $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
...

但是,当我按照说明操作并从-lcryptopp -lstlport_shared删除LOCAL_LDLIBS时,我会收到与libstlport_shared.so中的符号相关的链接错误。 Android.mk文件后面显示了错误示例。

ndk-build想要设置Android.mk的确切方式如何?

为什么我必须将$(STLPORT_INCL)添加到LOCAL_C_INCLUDES,将$(STLPORT_LIB)添加到LOCAL_LDFLAGS?为什么APP_STL := stlport_shared 正确设置STL?


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)

以下是从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()'

...

1 个答案:

答案 0 :(得分:10)

我在链接器标志中解释&#34;非系统库&#34;消息作为警告,您不使用默认系统库(在usr/lib中),这可能非常好,但也可能导致错误(不同库版本之间不兼容)。这个警告错误是否完全取决于你。

然后,关于你试图解决它的方式,我认为你错误地使用了NDK的LOCAL_SHARED_LIBRARIES变量。

我在此处粘贴了一个使用Assimp

Android.mk文件中的示例
#------------------------------------------------------------------ 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>

如您所见,我使用自定义名称声明LOCAL_MODULE,设置一些变量,然后包含PREBUILT_STATIC_LIBRARY脚本,告诉NDK使用此lib。

然后在LOCAL_STATIC_LIBRARIES中列出我使用的模块名称的库,而不是像你这样的链接器标记。

在您的情况下,我相信您应该执行以下操作,例如对于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 

我认为应该这样做。当然,重复每个导致问题的库的过程,并且不要忘记每个lib规范之间的include(CLEAR_VARS)