linux – 使用g的符号可见性

前端之家收集整理的这篇文章主要介绍了linux – 使用g的符号可见性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 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.
原文链接:https://www.f2er.com/linux/394477.html

猜你在找的Linux相关文章