在Linux静态库限制符号 [英] Restricting symbols in a Linux static library

查看:705
本文介绍了在Linux静态库限制符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找方法来限制​​出口到Linux静态库(存档)C符号的数量。我想这些限制为只有那些为图书馆的官方API的一部分符号。我已经使用了静态声明大多数功能为静态的,但是这限制了他们的文件范围。我正在寻找一种方式来限制范围的库。

I'm looking for ways to restrict the number of C symbols exported to a Linux static library (archive). I'd like to limit these to only those symbols that are part of the official API for the library. I already use 'static' to declare most functions as static, but this restricts them to file scope. I'm looking for a way to restrict to scope to the library.

我可以使用的技术在乌尔里希Drepper的如何写共享库共享库做到这一点,但我这些技术不能适用于静态档案。在他早期的图书馆设计纸张良好做法,他写道:

I can do this for shared libraries using the techniques in Ulrich Drepper's How to Write Shared Libraries, but I can't apply these techniques to static archives. In his earlier Good Practices in Library Design paper, he writes:

唯一的可能就是它需要所有的目标文件组合
  某些内部资源为一个使用LD -r,然后限制符号
  这是由该组合对象文件导出。 GNU的链接器选项
  做到这这一点。

The only possibility is to combine all object files which need certain internal resources into one using 'ld -r' and then restrict the symbols which are exported by this combined object file. The GNU linker has options to do just this.

谁能帮助我发现什么这些选项可能是什么?我已经有一些成功的'带-w -K prefix_ *',但这种感觉畜类。理想情况下,我想一个解决方案,将与GCC 3和4都工作。

Could anyone help me discover what these options might be? I've had some success with 'strip -w -K prefix_*', but this feels brutish. Ideally, I'd like a solution that will work with both GCC 3 and 4.

谢谢!

推荐答案

静态库为code不能做你想做的无论是与海湾合作委员会3.x或4.x的编译

Static libraries can not do what you want for code compiled with either GCC 3.x or 4.x.

如果您可以使用共享对象(库),GNU链接器做你所需要的一个功能叫做一个版本的脚本。这通常是用来提供特定版本的入口点,但退化的情况只是公共和私人符号区分没有任何版本。一个版本的脚本用--version脚本=命令行选项来指定LD

If you can use shared objects (libraries), the GNU linker does what you need with a feature called a version script. This is usually used to provide version-specific entry points, but the degenerate case just distinguishes between public and private symbols without any versioning. A version script is specified with the --version-script= command line option to ld.

版本脚本,使入口点foo和公示栏并隐藏所有其它接口的内容:

The contents of a version script that makes the entry points foo and bar public and hides all other interfaces:

{ global: foo; bar; local: *; };

请参阅ld DOC在: http://sourceware.org/binutils/文档/ LD / VERSION.html#版本

我的共享库的一大拥护者,而这种能力限制全局的可视性一个他们的伟大美德。

I'm a big advocate of shared libraries, and this ability to limit the visibility of globals is one their great virtues.

这提供了更多的共享对象的优点,但用于Solaris(由美好的回忆的Greg Nakhimovsky)编写的,文件是在的 http://developers.sun.com/solaris/articles/linker_mapfiles.html

A document that provides more of the advantages of shared objects, but written for Solaris (by Greg Nakhimovsky of happy memory), is at http://developers.sun.com/solaris/articles/linker_mapfiles.html

我希望这有助于。

这篇关于在Linux静态库限制符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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