简体   繁体   English

将预构建的静态和共享库与Android NDK链接时的问题

[英]Linking issue when prebuilt static and shared libraries with the Android NDK

I have a program I am porting that links together multiple libraries when creating the executable. 我有一个移植的程序,在创建可执行文件时将多个库链接在一起。 I have built all those libraries using the stand alone toolchain and using the standalone toolchain I am able to create an executable that works on an android device. 我使用独立的工具链构建了所有这些库,并使用独立的工具链,我能够创建一个可在Android设备上运行的可执行文件。 So, it seems like the libraries I have built are functional. 所以,我构建的库似乎是功能性的。 Now I am trying to incorporate those libraries with an app. 现在我正在尝试将这些库与应用程序合并。 So, in my android.mk I have something like this: 所以,在我的android.mk中我有这样的东西:

LOCAL_PATH := $(call my-dir)
ROOT_PATH := $(LOCAL_PATH)

include $(call all-subdir-makefiles)
include $(CLEAR_VARS)

LOCAL_PATH = $(ROOT_PATH)

LOCAL_MODULE    := test-libs

LOCAL_STATIC_LIBRARIES := staticA
LOCAL_SHARED_LIBRARIES := sharedA sharedB sharedC sharedD
LOCAL_SRC_FILES := test-libs.c

include $(BUILD_SHARED_LIBRARY)

For each of the libraries, I have a Android.mk like this 对于每个库,我都有像这样的Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := sharedA

LOCAL_SRC_FILES := libsharedA.so

include $(PREBUILT_SHARED_LIBRARY)

The static library and one of the shared libraries have no dependencies on anything and if I only include them all is cool. 静态库和其中一个共享库没有任何依赖关系,如果我只包含它们,那么一切都很酷。 One shared prebuilt library is dependent on the static prebuilt library only and the others are dependent on the prebuilt static library and other prebuilt shared libraries. 一个共享的预构建库仅依赖于静态预构建库,而其他库依赖于预构建的静态库和其他预构建的共享库。

The problem is if I load any that are dependent on the static library via System.loadLibrary() I get the useful message: 问题是如果我通过System.loadLibrary()加载任何依赖于静态库的东西我得到了有用的消息:

Unable to dlopen(libsharedA.so) Cannot load library: link_image

Digging through this and following the suggestions here about how to use strace: 深入研究并遵循以下有关如何使用strace的建议:

http://mpigulski.blogspot.com/2010/09/debugging-dlopen-unsatisfiedlinkerror.html http://mpigulski.blogspot.com/2010/09/debugging-dlopen-unsatisfiedlinkerror.html

I found that when the shared libraries are loaded, they cannot locate a function that is in my static library. 我发现加载共享库时,它们无法找到静态库中的函数。

So, how do I correctly use a prebuilt shared library whose use is dependent on a prebuilt static library and not have this issue? 那么,我如何正确使用预先构建的共享库,其使用依赖于预构建的静态库而没有此问题?

Shared libraries should not depend on static libraries. 共享库不应该依赖于静态库。

Static libraries are for linking (at compile-time) into an executable, not for adding at runtime. 静态库用于(在编译时)链接到可执行文件,而不是用于在运行时添加。

If your shared library A uses a static library B, then either build a shared version of B or include B when you link A together. 如果您的共享库A使用静态库B,则在将A链接在一起时构建B的共享版本或包含B.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM