我有2个不同库的源代码,FooMain和FooSecondary。 FooSecondary由FooMain使用,因此,makefile必须编译First FooSecondary,然后编译FooMain,然后将FooSecondary链接到FooMain。
我的Android.mk是:
LOCAL_PATH:= $(call my-dir) # Foo Secondary lib: # Clear vars include $(CLEAR_VARS) # Target Build LOCAL_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 support LOCAL_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 vars include $(CLEAR_VARS) # Include OpenCV include 3rdparty/OpenCV-2.4.3-rc-android-sdk/sdk/native/jni/OpenCV.mk # Target Build LOCAL_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 := libFooSecondary LOCAL_LDLIBS := -L$(LOCAL_PATH)/../libs/armeabi LOCAL_LDLIBS += -lz -lm -ldl -lGLESv2 -lEGL -llog -lFooSecondary LOCAL_CFLAGS := -O2 -mno-thumb -Wno-write-strings LOCAL_CPPFLAGS := -O2 -mno-thumb -Wno-write-strings # Compile as Shared Library include $(BUILD_SHARED_LIBRARY)
我的Application.mk是:
APP_CPPFLAGS := -frtti -fexceptions APP_STL := gnustl_static APP_ABI := armeabi-v7a
但是,当我使用ndk-build编译Android.mk时,我得到了下一个错误:
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,先编译第二个,我不知道为什么。
答案 0 :(得分:5)
你的Android.mk
看起来很奇怪。它在某处指定LOCAL_PATH
吗?没有必要将LOCAL_CPPFLAGS
分配给重复LOCAL_CFLAGS
,因为ndk-build会在C ++命令行上放置两组标志。
要更好地了解NDK如何解释您的 Application.mk 和 Android.mk ,您可以运行
ndk-build V=1
这将回显所有已执行的命令,包括编译和链接,以及NDK构建的所有参数。
答案 1 :(得分:2)
尝试将FooSecondary编译为静态库,并将其包含在FooMain中: LOCAL_STATIC_LIBRARIES:= libFooSecondary
ndk并不能很好地与多个共享库一起使用,除非他们正在进行dlopen&#39;