GNU链接器:--version-script的替代方法,可以在命令行中列出导出的符号? [英] GNU linker: alternative to --version-script to list exported symbols at the command line?

查看:2010
本文介绍了GNU链接器:--version-script的替代方法,可以在命令行中列出导出的符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在具有GNU工具链的Linux上,我知道如何使用版本脚本(gcc -Wl,-version-script = symbols.map)控制共享库中的导出符号,但是我想在命令行代替. IOW,我想要相当于

On Linux with the GNU toolchain, I know how to control exported symbols from a shared library with a version script (gcc -Wl,--version-script=symbols.map), but I would like to list exported symbols on the command line instead. IOW, I would like the equivalent of

link /EXPORT:foo 

来自MS工具链.有可能吗?

from the MS toolchain. Is it possible ?

我的问题可能还不太清楚:如果我有一个库libfoo.so,并且我只想导出库foo1和foo2,则可以按照以下步骤创建版本脚本foo.linux

My question may not be very clearn: if I have a library libfoo.so, and I want to only export libraries foo1 and foo2, I can go create a version script foo.linux as follows

libfoo.so
{
global:
    foo1;
    foo2;
local:
    *;
}

然后做

gcc -shared foo.c -Wl,--version-script=foo.linux -o libfoo.so -soname libfoo.so

我希望能够执行以下操作:

I would like to be able to do something like this instead:

gcc -shared foo.c -Wl,--export-symbol=foo1 -Wl,--export-symbol=foo2 -o libfoo.so -soname libfoo.so

推荐答案

我不确定您可以按照自己的意愿执行此操作. 一种方法是使用您提到的链接器版本脚本.另一种方法是为要导出的内容添加源代码__attribute__ ((visibility("default"))),并使用-fvisibility=hidden

I'm not sure that you can do this like you want. One way is with the linker version script like you mentioned. Another way is to add in your source code __attribute__ ((visibility("default"))) for whatever you want exported and compile everything with -fvisibility=hidden

这篇关于GNU链接器:--version-script的替代方法,可以在命令行中列出导出的符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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