我有 2 个不同库的源代码,FooMain 和 FooSecondary。 FooSecondary 被FooMain 使用,所以makefile 必须先编译FooSecondary,再编译FooMain,再将FooSecondary 链接到FooMain。
我的 Android.mk 是:
LOCAL_PATH:= $(call my-dir)# Foo Secondary lib:# Clear varsinclude $(CLEAR_VARS)# Target BuildLOCAL_ARM_MODE := arm # Library Name LOCAL_MODULE := FooSecondary # Set All SRC_FILES Together SRC_FILES := $(wildcard $(LOCAL_PATH)/FooSecondary/src/*.c)SRC_FILES := $(SRC_FILES:$(LOCAL_PATH)/%=%) LOCAL_SRC_FILES = $(SRC_FILES)# Enable Log supportLOCAL_LDLIBS = -llog # C Flags - Max optimization LOCAL_CFLAGS := -O3 -mno-thumb# C++ Flags - Max optimization LOCAL_CPPFLAGS := -O3 -mno-thumb# Compile as Shared Library include $(BUILD_SHARED_LIBRARY) # Foo Secondary lib:# Clear varsinclude $(CLEAR_VARS)# Include OpenCVinclude 3rdparty/OpenCV-2.4.3-rc-android-sdk/sdk/native/jni/OpenCV.mk# Target BuildLOCAL_ARM_MODE := arm # Library Name LOCAL_MODULE := FooMain # Set All SRC_FILES Together SRC_FILES := $(wildcard $(LOCAL_PATH)/FooMain/src/*.cpp)SRC_FILES := $(SRC_FILES:$(LOCAL_PATH)/%=%) LOCAL_SRC_FILES = $(SRC_FILES)LOCAL_SHARED_LIBRARIES := libFooSecondaryLOCAL_LDLIBS := -L$(LOCAL_PATH)/../libs/armeabi LOCAL_LDLIBS += -lz -lm -ldl -lGLESv2 -lEGL -llog -lFooSecondaryLOCAL_CFLAGS := -O2 -mno-thumb -Wno-write-stringsLOCAL_CPPFLAGS := -O2 -mno-thumb -Wno-write-strings# Compile as Shared Library include $(BUILD_SHARED_LIBRARY)
And my Application.mk is:
APP_CPPFLAGS := -frtti -fexceptionsAPP_STL := gnustl_staticAPP_ABI := armeabi-v7a
But, when I compile Android.mk using ndk-build I get the next Error:
Compile arm : libFooSecondary <= *.c
SharedLibrary : libFooSecondary.so
Install : libFooSecondary.so => libs/armeabi-v7a/libFooSecondary.so
SharedLibrary : libFooMain.so
/home/user/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -lFooSecondary
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libFooMain.so] Error 1
为什么正确编译安装了libFooSecondary.so却找不到?
此外,如果 LOCAL_MODULE 名称更改,例如,第一个是 LOCAL_MODULE := zname,第二个是 LOCAL_MODULE := aname,则先编译第二个,我不知道为什么。
您的 Android.mk
看起来很奇怪。它是否在某处分配了 LOCAL_PATH
?无需将 LOCAL_CPPFLAGS
分配给重复的 LOCAL_CFLAGS
,因为 ndk-build 将两组标志都放在 C++ 命令行上。
要更好地了解 NDK 如何解释您的 Application.mk 和 Android.mk,您可以运行
ndk-build V=1
这将回显所有已执行的命令,包括编译和链接,以及 NDK 构建分配的所有参数。
我是一名优秀的程序员,十分优秀!