7

我在运行时收到此警告$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_sharedLOCAL_LDLIBS,我会收到与来自 的符号相关的链接错误libstlport_shared.soAndroid.mk文件后面显示了错误示例。

究竟ndk-build要如何Android.mk设置?

为什么我必须添加$(STLPORT_INCL)toLOCAL_C_INCLUDES$(STLPORT_LIB)to 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()'

...

4

1 回答 1

11

我将“链接器标志中的非系统库”消息解释为警告您没有使用默认系统库(in usr/lib),这可能非常好,但也可能导致错误(不同库版本之间的不兼容)。这个警告是否让您感到不安完全取决于您。

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

Android.mk我从我的一个使用 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>

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

然后在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 

我认为应该这样做。当然,对每个引起麻烦的库重复这个过程,不要忘记include(CLEAR_VARS)每个库规范之间的关系。

于 2014-09-04T12:13:34.647 回答