加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 使用g的符号可见性

发布时间:2020-12-13 18:49:38 所属栏目:Linux 来源:网络整理
导读:我在 Linux / Mac下编译了一个隐藏了符号的C库.我已经为我的所有类使用了_attribute_((visibility(“hidden”)))并使用选项编译(-c -O2 -fPIC -MMD -MP -MF).在Mac下,使用MacDependencies(http://code.google.com/p/macdependency/),工作完成得很好,因为我只
我在 Linux / Mac下编译了一个隐藏了符号的C库.我已经为我的所有类使用了_attribute_((visibility(“hidden”)))并使用选项编译(-c -O2 -fPIC -MMD -MP -MF).在Mac下,使用MacDependencies(http://code.google.com/p/macdependency/),工作完成得很好,因为我只看到我的导出(我实际上看到了之前和之后的差异).

但是,我注意到使用nm我仍然可以看到符号的所有名称.这种情况发生在Mac和Linux下.

这是为什么?有什么方法可以避免这种情况吗?

最诚挚的问候和感谢,

解决方法

公共或隐藏的符号仍然存在. nm显示所有符号.不同之处在于隐藏符号不可用于动态链接器,即不导出且不能插入.

您可能也喜欢以下man gcc:

-fvisibility=default|internal|hidden|protected
       ...
       A good explanation of the benefits offered by ensuring ELF symbols
       have the correct visibility is given by "How To Write Shared
       Libraries" by Ulrich Drepper (which can be found at
       <http://people.redhat.com/~drepper/>)---however a superior solution
       made possible by this option to marking things hidden when the
       default is public is to make the default hidden and mark things
       public.  This is the norm with DLL's on Windows and with
       -fvisibility=hidden and "__attribute__ ((visibility("default")))"
       instead of "__declspec(dllexport)" you get almost identical
       semantics with identical syntax.  This is a great boon to those
       working with cross-platform projects.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读