How to compile two different libraries in one Android.mk linking one of them with the other

I have source code from two different libraries: FooMain and FooSecondary. FooSecondary is used by FooMain, so the makefile must compile First FooSecondary, then compile FooMain, and then associate FooSecondary with FooMain.

My 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) 

And my Application.mk:

  APP_CPPFLAGS: = -frtti -fexceptions
 APP_STL: = gnustl_static
 APP_ABI: = armeabi-v7a

But when I compile Android.mk using ndk-build, I get the following 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 is libFooSecondary.so not found if it is compiled and installed correctly?

Additionally, if the name LOCAL_MODULE changes, for example, the first is LOCAL_MODULE: = zname and the second is LOCAL_MODULE: = aname, compile the second first, I don’t know why.

+4
source share
2 answers

Your Android.mk looks weird. Does it describe LOCAL_PATH somewhere? There is no need to assign LOCAL_CPPFLAGS to duplicate LOCAL_CFLAGS , because ndk-build puts both sets of flags in the C ++ command line.

To better understand how the NDK interprets your Application.mk and Android.mk , you can run

 ndk-build V=1 

This will reflect all the executed commands, including compilation and the link, with all their parameters that the NDK assembly assigns.

+5
source

Try compiling FooSecondary as a static library and including it in FooMain as: LOCAL_STATIC_LIBRARIES: = libFooSecondary

ndk does not play well with multiple shared libraries unless they are unpacked.

+2
source

Source: https://habr.com/ru/post/1442785/


All Articles