Android.mk: shared library not linked

I am trying to include my library libtest.so into another library.

libtest.so is successfully compiled and in the folder:

$PROJECT/obj/local/armeabi/libtest.so

When I tried to use it in my Android.mk file, I couldn't use its functionality. I didn't get an error message however, not even if I included a library that doesn't exist.

This is my Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

#LOCAL_SHARED_LIBRARY := test
LOCAL_SHARED_LIBRARIES := test

LOCAL_MODULE     := mylib
LOCAL_SRC_FILES  := myLib.cpp

include $(BUILD_SHARED_LIBRARY)

When I built this, I just got a lot of "No such file or directory" errors from my includes from the library:

jni/myLib.cpp:10:24: error: myinclude.h: No such file or directory

myinclude.h is a file from the library. Every forum answer seems to say that LOCAL_SHARED_LIBRARIES := test or LOCAL_SHARED_LIBRARIES := libtest would be enough to use the library.

What am I missing?

Answers


add the directory which contain myinclude.h to LOCAL_C_INCLUDES:

LOCAL_C_INCLUDES += /dir/to/your/include/files/

Since it's the library's responsibility to tell you what to include, despite that it may solve the problem temporarily, using LOCAL_C_INCLUDES to specify include files written by somebody else (as suggested in the answer by Gavin) is not a good idea in terms of maintainability.

One of the problems is that your problem is that the Android.mk file of libtest is not correctly written. If it exports any header files, you should add LOCAL_EXPORT_C_INCLUDES := /path/to/include-dir to it.

Here is an example (taken from $NDK_ROOT/samples/module-exports/jni/Android.mk):

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo/foo.c
LOCAL_CFLAGS := -DFOO=2
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo
LOCAL_EXPORT_CFLAGS := -DFOO=1
LOCAL_EXPORT_LDLIBS := -llog
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := bar
LOCAL_SRC_FILES := bar/bar.c
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/bar
LOCAL_STATIC_LIBRARIES := foo
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := zoo
LOCAL_SRC_FILES := zoo/zoo.c
LOCAL_SHARED_LIBRARIES := bar
include $(BUILD_SHARED_LIBRARY)

Here, the first library is foo. It is built as a static library (see include $(BUILD_STATIC_LIBRARY)). It exports the header directory with:

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo

The second library is bar, it is a shared library (see LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/bar). When it references foo with:

LOCAL_STATIC_LIBRARIES := foo

the headers in foo will be search as if -I$LOCAL_PATH/foo has been specified to gcc. Note that it also export its own header directory with:

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/bar

The third library is zoo, it is a shared library. It references the bar library. This demonstrates that a shared library can include another shared library without any problem.

Please include more of your configurations if this doesn't solve your problem.


Need Your Help

Switch statement of string

java android switch-statement

I'm trying to use a switch statement in a Android Application. This switch statement is testing the value of a String, and then based of that changing the value of another String.

is it possible to pass parameters between jquery files

javascript php jquery

is it possible to pass parameters between jquery files because I have a function.php page which displays products from my database and a comments box for each product on my products page, the funct...