I have source code of 2 different libraries, FooMain and FooSecondary. FooSecondary is used by FooMain, so, makefile must compile First FooSecondary, then compile FooMain, and then link FooSecondary to FooMain.
My Android.mk is:
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)
And my Application.mk is:
APP_CPPFLAGS := -frtti -fexceptions APP_STL := gnustl_static APP_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
Why libFooSecondary.so is not found if is correctly compiled and installed?
Additionaly, if LOCAL_MODULE name change, for example, first one is LOCAL_MODULE := zname and second one is LOCAL_MODULE := aname, compile first the second one, i don't know why.
Android.mk looks weird. Does it assign
LOCAL_PATH somewhere? There is no need to assign
LOCAL_CPPFLAGS to duplicate
LOCAL_CFLAGS, because ndk-build puts both sets of flags on C++ command line.
To understand better how NDK interprets your Application.mk and Android.mk, you can run
This will echo all executed commands, including compilation and link, with all their parameters that NDK build assigns.
Try compiling FooSecondary as a static library and include it in FooMain as: LOCAL_STATIC_LIBRARIES := libFooSecondary
The ndk doesn't play nicely with multiple shared libraries unless they're being dlopen'd.