两个共享库(有一些相同的源代码)不能同时加载?

发布于 2024-09-27 15:27:23 字数 493 浏览 0 评论 0原文

  • 开发工具 : Sun Studio 11
  • Flags : CXXFLAGS=-O2 -g

我有两个共享库, libA.so libB.so :

  • /A/root.cpp /A/a.cpp 用于生成 libA.so
  • /B/root .cpp /B/b.cpp用于生成libB.so
  • /A/root.cpp和/B/root.cpp等同于

libA.so,libB.so在主程序运行时会在

加载libA.so时 动态加载然后加载libB.so,libB.so会打印以下调试信息: /B/b.cpp:...... /A/root.cpp : ...

当加载 libB.so 然后加载 libA.so 时,libA.so 将打印以下调试信息:

/A/a.cpp : .....
/B/root.cpp : ...

为什么?

  • Development Tool : Sun Studio 11
  • Flags : CXXFLAGS=-O2 -g

I have two shared libraries, libA.so libB.so :

  • /A/root.cpp /A/a.cpp are used to generate libA.so
  • /B/root.cpp /B/b.cpp are used to generate libB.so
  • /A/root.cpp and /B/root.cpp is identifical

libA.so and libB.so will be dynamically loaded during main program running

when loading libA.so and then loading libB.so, libB.so will print the following debug info:
/B/b.cpp : .....
/A/root.cpp : ...

when loading libB.so and then loading libA.so, libA.so will print the following debug info:

/A/a.cpp : .....
/B/root.cpp : ...

Why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄风 2024-10-04 15:27:23

如果您尝试静态编译它,链接器会抱怨多个定义。看起来加载程序已经感到困惑并试图优雅地失败。

http://uw714doc.sco.com/en/SDK_cprog/CCCS_LinkEdit.html#CCCS_HdlMultDefdSyms

If you tried to compile this statically, the linker would complain about multiple definitions. Looks like the loader has gotten confused and is trying to fail gracefully.

http://uw714doc.sco.com/en/SDK_cprog/CCCS_LinkEdit.html#CCCS_HdlMultDefdSyms

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文