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

vgonisanz 10/29/2012. 2 answers, 4.235 views
opencv android-ndk android-ndk makefile

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.

2 Answers


Alex Cohn 10/29/2012.

Your 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

ndk-build V=1

This will echo all executed commands, including compilation and link, with all their parameters that NDK build assigns.


AnthonyS 10/30/2012.

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.


HighResolutionMusic.com - Download Hi-Res Songs

1 The Chainsmokers

Beach House flac

The Chainsmokers. 2018. Writer: Andrew Taggart.
2 (G)I-DLE

POP/STARS flac

(G)I-DLE. 2018. Writer: Riot Music Team;Harloe.
3 Anne-Marie

Rewrite The Stars flac

Anne-Marie. 2018. Writer: Benj Pasek;Justin Paul.
4 Ariana Grande

​Thank U, Next flac

Ariana Grande. 2018. Writer: Crazy Mike;Scootie;Victoria Monét;Tayla Parx;TBHits;Ariana Grande.
5 Diplo

Close To Me flac

Diplo. 2018. Writer: Ellie Goulding;Savan Kotecha;Peter Svensson;Ilya;Swae Lee;Diplo.
6 BTS

Waste It On Me flac

BTS. 2018. Writer: Steve Aoki;Jeff Halavacs;Ryan Ogren;Michael Gazzo;Nate Cyphert;Sean Foreman;RM.
7 Clean Bandit

Baby flac

Clean Bandit. 2018. Writer: Jack Patterson;Kamille;Jason Evigan;Matthew Knott;Marina;Luis Fonsi.
8 Imagine Dragons

Bad Liar flac

Imagine Dragons. 2018. Writer: Jorgen Odegard;Daniel Platzman;Ben McKee;Wayne Sermon;Aja Volkman;Dan Reynolds.
9 BlackPink

Kiss And Make Up flac

BlackPink. 2018. Writer: Soke;Kny Factory;Billboard;Chelcee Grimes;Teddy Park;Marc Vincent;Dua Lipa.
10 Nicki Minaj

No Candle No Light flac

Nicki Minaj. 2018. Writer: Denisia “Blu June” Andrews;Kathryn Ostenberg;Brittany "Chi" Coney;Brian Lee;TJ Routon;Tushar Apte;ZAYN;Nicki Minaj.
11 Rita Ora

Cashmere flac

Rita Ora. 2018. Writer: Sean Douglas;Lindy Robbins.
12 Backstreet Boys

Chances flac

Backstreet Boys. 2018.
13 Brooks

Limbo flac

Brooks. 2018.
14 Rita Ora

Velvet Rope flac

Rita Ora. 2018.
15 Fitz And The Tantrums

HandClap flac

Fitz And The Tantrums. 2017. Writer: Fitz And The Tantrums;Eric Frederic;Sam Hollander.
16 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.
17 Cher Lloyd

None Of My Business flac

Cher Lloyd. 2018. Writer: ​iamBADDLUCK;Alexsej Vlasenko;Kate Morgan;Henrik Meinke;Jonas Kalisch;Jeremy Chacon.
18 Billie Eilish

When The Party's Over flac

Billie Eilish. 2018. Writer: Billie Eilish;FINNEAS.
19 Kelly Clarkson

Never Enough flac

Kelly Clarkson. 2018. Writer: Benj Pasek;Justin Paul.
20 Lil Pump

Arms Around You flac

Lil Pump. 2018. Writer: Rio Santana;Lil Pump;Edgar Barrera;Mally Mall;Jon Fx;Skrillex;Maluma;Swae Lee;XXXTENTACION.

Related questions

Hot questions

Language

Popular Tags