Android的静态链接VS针对glibc的动态链接 [英] Android Static Linking vs Dynamic Linking against glibc

查看:1224
本文介绍了Android的静态链接VS针对glibc的动态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在交叉编译一些Linux工具(和我自己的一些C code)到Android和我面对的是,Android的libc中有一些缺失/剥离部件和我结束了修补我的挑战之一code,使其与Android的libc的工作(例如对于一个像这样的<一个问题href="http://credentiality2.blogspot.com/2010/08/compile-ncurses-for-android.html">http://credentiality2.blogspot.com/2010/08/compile-ncurses-for-android.html)

I have been cross-compiling some Linux tools (and some of my own C code) to Android and one of the challenges that I face is that Android's libc has some missing/stripped components and I end up patching my code to make it work with Android's libc (for e.g. a problem like this http://credentiality2.blogspot.com/2010/08/compile-ncurses-for-android.html)

Q1:我如何去静态链接的是glibc(和其他相关性),而交叉编译的胳膊工具链(或NDK建造)?

Q1 : How do I go about statically linking against glibc (and other dependencies) while cross-compiling with the arm toolchain (or ndk-build)?

Q2:这是个好主意静态对glibc的链接以二进制为Android?我应该期待什么突破,如果我开始静态链接?是否有任何性能/内存问题?

Q2 : Is it a good idea to statically link against glibc for binaries for Android? Should I expect anything to break if I start statically linking? Are there any performance/memory issues?

据我所知大部分静态VS动态链接的优劣从这里 - <一href="http://stackoverflow.com/questions/2095363/c-application-should-i-use-static-or-dynamic-linking-for-the-libraries">C++应用 - 我应该使用静态或动态链接的库并? 静态链接VS动态链接

I understand most of the pros and cons of static vs dynamic linking from here - C++ application - should I use static or dynamic linking for the libraries? and Static linking vs dynamic linking

所以,我想知道我是否应该静态链接的glibc为Android时,交叉编译的二进制文件。

So I wish to know if I should be statically linking glibc for Android when cross-compiling binaries.

推荐答案

首先一个小纸条上的libc。而Android的libc是仿生的libc( https://github.com/android/platform_bionic/ ),而比GNU库(glibc的)。因此,包含在NDK的libc的是仿生的,因为是的libc在Android设备上。

First a small note on the libc. The Android libc is the Bionic libc (https://github.com/android/platform_bionic/) rather than the GNU libc (glibc). Thus the libc contained in the NDK is Bionic, as is the libc available on android devices.

至于glibc的而言,它是可以与NDK编译它。然而,这是在Android设备上安装的名字将与该系统的libc冲突。请注意,这只是如果你去构建一个动态库。如果你建立了GNU libc中的静态库,那么上面的整个问题是回避,因为你永远需要安装一个静态库。

As far as glibc is concerned, it is possible to build it with the NDK. However, it's name will clash with the system libc when installed on android devices. Note that this is only if you go for building a dynamic library. If you build the GNU libc as a static library, then the whole issue above is sidestepped, as you never need to install a static library.

现在回答你的问题:

  1. Q1:如果您正在构建使用NDK glibc的,那么Android.mk使用变量BUILD_STATIC_LIBRARY构建静态库。但是,如果你不使用NDK,那么你可能需要进入的很多头疼的(不知道有多少)。我不能告诉你更多关于这个,因为我还没有尝试过的glibc的版本,无论是静态还是动态的。此外,似乎静态链接用glibc的强烈反对,在 - 至少对非移动平台。

  1. Q1: If you're building the glibc using the NDK, then the Android.mk uses the variable BUILD_STATIC_LIBRARY to build static libraries. However, if you dont use the NDK, then you'll probably need to get into the a lot of headache(dont know how much). I can't tell you more on this as I haven't tried a build of glibc, either static or dynamic. Also, it seems that static linking with glibc is highly discouraged, at-least for non-mobile platforms.

从破损的观点,有静态和动态链接之间没有差异。从一个启​​动观点来看,静态可执行启动作为不需要的动态库加载步骤更快。有一个在静态或动态链接的可执行文件没有记忆或执行速度损失。磁盘存储的要求是静态的可执行文件较大。

From a breakage viewpoint, there is no difference between static and dynamic linking. From a start-up viewpoint, a static executable start up faster as the dynamic libraries loading step is not needed. There is no memory or execution speed penalty in either static or dynamic linked executables. Disk storage requirement is larger for static executables.

至于问题与仿生libc中缺失的功能,您可以使用由大多数GNU软件,这是方法,提供自己的情况下,它是从系统库中缺少的功能。我编译的文件5.11,GNU使3.82,diffutils-2.8的Andr​​oid传递NDK工具链/包括/库来自动工具时(./configure ...)。看来,这些方案包含的大部分非核心库函数的实现方式中,在的情况下的标准库不提供这些信息(在这种情况下,仿生)。

As far as problems with the bionic libc missing functionality, you can use the method used by most GNU software, which is, provide your own implementation of a function in case it is missing from the system libraries. I've compiled file-5.11, GNU make 3.82, diffutils-2.8 for Android passing the NDK toolchains/includes/libs to autotools (./configure ...). It seems that these programs contain implementations of most of the non-core library function, in case the standard libraries dont provide them (in this case Bionic).

注:我会试着建立一个静态的glibc和更新的答案,当我成功/失败

Note: I'll try and build a static glibc and update the answer as and when I succeed/fail.

这篇关于Android的静态链接VS针对glibc的动态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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