Android本机可执行文件链接到本机共享库

时间:2014-09-10 12:05:37

标签: android-ndk shared-libraries native executable dynamic-linking

我使用ndkbuid编译了两个不同的native so文件。当他们链接android java aplication时,它们正常运行。现在我想在我的原生可执行文件中也使用它们。为了实现这一点,我使用以下Android.mk,因此我的可执行文件正在编译而没有任何问题:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) 
LOCAL_C_INCLUDES := some include folders
LOCAL_C_INCLUDES += some include folders1
LOCAL_C_INCLUDES += some include folders2
LOCAL_C_INCLUDES += some include folders3
LOCAL_C_INCLUDES += some include folders4
LOCAL_MODULE    := hello_world  
LOCAL_SRC_FILES := hello.c
LOCAL_LDLIBS += -L/Projects/workspace/mylib/libs/armeabi -lmylib
LOCAL_LDLIBS += -L/Projects/workspace/mylib1/libs/armeabi -lmylib1
LOCAL_LDLIBS += -L/$HOME/out/target/product/evm/system/lib  -lcrypto 
include $(BUILD_EXECUTABLE)

我的hello.c是:

int main ( int argc,char **argv )
{
    int a=foo(); //foo is in libmylib.so;

    return 0;
}

我只是将mylib.so和mylib1.so文件复制到/ system / lib文件夹。 。但是当我尝试在命令行中使用“./hello_world”运行我的应用程序时,它会在链接时崩溃。我的应用程序是纯本机代码所以我不知道我是否必须使用nativeactivity或其他东西。

我还使用以下Android.mk

编译共享库
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := /$HOME/include
LOCAL_MODULE    := mylib
LOCAL_SRC_FILES := some sources
LOCAL_LDLIBS := -lz #-L$(PATH_TO_FOO) 
APP_CFLAGS := -g
include $(BUILD_SHARED_LIBRARY)

请提出任何建议。

0 个答案:

没有答案