链接elf应用程序和共享库时选择导出的符号 [英] choose exported symbols when linking an elf application and shared library
问题描述
当链接一个elf应用程序或共享库时,我想选择要导出的符号.默认情况下,链接应用程序时不导出任何功能符号,而链接共享库时则导出所有功能符号.有什么方法可以控制要导出的符号?链接应用程序时,我可以使用 -rdynamic
或 -Wl,-export-dynamic
来获取所有符号,并且我可以使用 -Wl,-动态列表< symfile>
来仅获取一些符号.但是,在链接库时,这些选项会被忽略吗?
when linking an elf application or share library, I want to choose which symbols to export. By default, when linking an application no function symbol is exported and when linking a shared library all function symbols are exported. Is there any way to control which symbols to export? When linking an application, I can use -rdynamic
or -Wl,--export-dynamic
to get all symbols, and I can use -Wl,--dynamic-list <symfile>
to get only some symbols. However when linking a library, are those options ignored?
推荐答案
稍作测试后发现:
-
对于ELF应用程序,可以使用
-rdynamic
或-Wl,-export-dynamic
导出所有符号,也可以使用-Wl,-dynamic-list< sym-file>
通过gcc
链接应用程序时仅导出一些符号.
for ELF applications, you can use
-rdynamic
or-Wl,--export-dynamic
to export all symbols, or you can use-Wl,--dynamic-list <sym-file>
to export only some symbols when linking your application throughgcc
.
对于ELF库,不能使用 -rdynamic
, -Wl,-export-dynamic
或 -Wl,-dynamic-list< symfile>
,通过 gcc
链接库时,必须使用 -Wl,-version-script =< verfile>
.
for ELF libraries, you can't use -rdynamic
, -Wl,--export-dynamic
or -Wl,--dynamic-list <symfile>
, you must use -Wl,--version-script=<verfile>
when linking your library through gcc
.
版本脚本和sym-file几乎相同,除了对sym-file而言,您不编写版本和范围.文档: gnu ld
The version-script and the sym-file are almost the same, except that for sym-file you do not code a version and a scope. Documentation: gnu ld
这篇关于链接elf应用程序和共享库时选择导出的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!