构建链接到其他非标准共享库的共享库

时间:2012-03-01 14:11:34

标签: android c++ gcc android-ndk shared-libraries

我有两个共享库和标头。 我想使用前两个库中的函数构建第三个共享库。 我觉得makefile有问题。当我尝试构建时收到这个:

Android NDK: /cygdrive/d/.../jni/Android.mk: Cannot find module with tag 'shared1' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
/cygdrive/d/.../jni/Android.mk:36: *** Android NDK: Aborting.    .  Stop.

我项目的结构:

jni/
 - myfile.c
 - Android.mk
   jni/dec/
     - lot of header files
   jni/enc/
     - lot of header files
libs/armeabi/
 - shared1.so
 - shared2.so

也是Android.mk sourse:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES :=   \
    $(LOCAL_PATH)/dec \
    $(LOCAL_PATH)/enc 

LOCAL_SHARED_LIBRARIES := shared1 shared2

LOCAL_MODULE    := mylib
LOCAL_SRC_FILES := myfile.c
LOCAL_LDLIBS    += -lOpenSLES
LOCAL_LDLIBS    += -llog
LOCAL_LDLIBS    += -landroid

include $(BUILD_SHARED_LIBRARY)

$(call import-module, shared1)
$(call import-module, shared2)

2 个答案:

答案 0 :(得分:5)

看看这个问题:Android JNI APK Packing

您需要为libs/armeabi/文件夹指定另一个名称,以避免与NDK构建冲突,并在include $(CLEAR_VARS)语句之前添加以下代码:

include $(CLEAR_VARS)
LOCAL_MODULE:=shared1
LOCAL_SRC_FILES:=3rdparty_libs/shared1.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE:=shared2
LOCAL_SRC_FILES:=3rdparty_libs/shared2.so
include $(PREBUILT_SHARED_LIBRARY)

答案 1 :(得分:2)

据我了解,正确的方法是使用ndk-build而不是直接调用编译器。

在Android.mk中,您需要为要编译的每个静态库指定一个模块,然后指定您的共享库应该使用它。

hello-jni示例项目的修改后的Android.mk文件示例:

LOCAL_PATH := $(call my-dir)

# Define vars for library that will be build statically.
include $(CLEAR_VARS)
LOCAL_MODULE := <module_name>
LOCAL_C_INCLUDES := <header_files_path>
LOCAL_SRC_FILES :=  <list_of_src_files>

# Optional compiler flags.
LOCAL_LDLIBS   = -lz -lm
LOCAL_CFLAGS   = -Wall -pedantic -std=c99 -g

include $(BUILD_STATIC_LIBRARY)

# First lib, which will be built statically.
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_STATIC_LIBRARIES := <module_name>
LOCAL_C_INCLUDES := <header_files_path>
LOCAL_SRC_FILES := hello-jni.c

include $(BUILD_SHARED_LIBRARY)

如果要在运行ndk-build时控制要编译的模块,可以创建一个Application.mk文件(与Android.mk在同一目录中)并列出所有模块,如下例所示:

APP_MODULES := <module_name_1> <module_name_2> ... <module_name_n>

我认为它有助于你