如何防止从静态链接库导出符号?
我在 linux x86 上创建了一个共享库。在创建它时,我在 openssl 中静态链接。 OpenSSL 仅在内部使用,但我看到 openssl 符号已被导出。这会给需要我的库和 openssl 的其他库带来问题,因为可能在运行时加载错误的符号。当我静态链接到我的共享库时,有没有办法防止所有 openssl 符号被导出?
谢谢, 麦克风
I have created a shared library on linux x86. In creating it, I have statically linked in openssl. OpenSSL is only used internally however I see that the openssl symbols have been exported. This is causing problems for other libraries that need my library AND openssl because the wrong symbol can be loaded at runtime. Is there a way to prevent all of the openssl symbols from getting exported when I statically link it into my shared library?
Thanks,
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用的是 gcc,在链接库时,设置 -fvisibility=hidden 并在库源中将所有您希望可见的函数标记为 extern。我认为只要 openssl 没有声明自己的函数 extern 就应该可以工作。
我认为如果 openssl 声明了一些符号 extern,您可以手动强制使用编译指示隐藏符号。
还有其他选项。请查看 fvisibility 部分中的 gcc 文档,以获取可用内容的完整说明。
Assuming you are using gcc, when linking your library, set -fvisibility=hidden and in your library source, mark all of the functions you want to be visible as extern. I think this should work as long as openssl has not declared their own functions extern.
I think if openssl has declared some symbols extern, you can manually force symbols to be hidden with pragmas.
There are other options involved. Check the gcc docs in the fvisibility section for a full explanation of what is available to you.