链接问题,当prebuilt静态和共享库的Andr​​oid NDK [英] Linking issue when prebuilt static and shared libraries with the Android NDK

查看:238
本文介绍了链接问题,当prebuilt静态和共享库的Andr​​oid NDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建可执行文件时程序,我是移植一起链接多个库。我已经建立了所有那些使用独立的工具链和使用独立的工具链,我能够创建在Android设备上工作的可执行文件库。因此,它似乎像我所建的库功能。现在我试图将这些库与一个应用程序。所以,在我android.mk我有这样的事情:

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. 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:

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)

有关每个库,我有一个Android.mk这样

For each of the libraries, I have a Android.mk like this

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := sharedA

LOCAL_SRC_FILES := libsharedA.so

include $(PREBUILT_SHARED_LIBRARY)

静态库和共享库中的一个对任何事情没有依赖性,如果我只包括他们都很酷。一个共享prebuilt库是依赖于静态prebuilt只有图书馆和其他人都依赖于prebuilt静态库等prebuilt共享库。

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.

问题是如果我加载任何依赖于通过的System.loadLibrary(静态库),我得到的有用信息:

The problem is if I load any that are dependent on the static library via System.loadLibrary() I get the useful message:

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

通过这个挖掘和这里下面有关如何使用strace的建议:

Digging through this and following the suggestions here about how to use strace:

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.

那么,如何正确地使用prebuilt共享库,其使用依赖于prebuilt静态库,而不是有这个问题?

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.

如果您的共享库中使用静态库B,那么无论是打造B的共享版本,或者包括B当您链接在一起。

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.

这篇关于链接问题,当prebuilt静态和共享库的Andr​​oid NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆