与 ifort 和 .so 库的正确链接顺序
我有两个第 3 方库 A.so 和 B.so,我将它们与我的可执行文件executable.exe 链接在一起。 A.so 包含一个已由 B.so 解决的错误,即:
A::subroutine1()
调用时可能会因浮点异常而崩溃(FP 算术错误)B ::subroutine1()
是一个固定实现,应始终调用它而不是A::subroutine1()
。
A 和 B 的正确链接顺序是什么?我现在正在做的是:
ifort <....> executable.exe <...> -lA -lB
我仍然时不时地收到浮点异常(该错误无法准确重现,因此很难调试)。然而,当它崩溃时,程序让我知道 A::subroutine1() 是违规者 - 因此由于某种原因链接了错误版本的 subroutine1() 。
我将翻转链接顺序作为第一个尝试,但是是否有一个工具可以用来检查executable.exe以查看在运行时将调用哪个版本的subroutine1()?
谢谢!
I have two 3rd party libraries A.so and B.so that I am linking together with my executable executable.exe. A.so contains a bug that is addressed by B.so, that is, say:
A::subroutine1()
may crash with a floating point exception when called (FP arithmetic bug)B::subroutine1()
is a fixed implementation that should always be called instead ofA::subroutine1()
.
What is the correct linking order for A and B? What I am doing now is:
ifort <....> executable.exe <...> -lA -lB
I am still getting the floating point exception from time to time (the error is not reproducible exactly, so it's pretty difficult to debug). However, when it crashes, the program lets me know that A::subroutine1() is the offender - so the wrong version of subroutine1() gets linked in for some reason.
I will flip the linking order as a 1st stab at this, but is there a tool that I can use to inspect executable.exe to see what version of subroutine1() will be called at runtime?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望调用
libB.so
中的subroutine1
,那么正确的链接顺序是-lB -lA
(对于 Linux 和大多数其他 UNIX 共享库实现)。否:该信息通常不会记录在可执行文件中。规则是:首先定义 subroutine1 的共享库将被使用。
例如,如果您使用
-lC -lB -lA
进行链接,并且在链接时libC.so
确实不定义subroutine1< /code>,但稍后您重建
libC.so
(无需重新链接可执行文件),然后从libC 重建
subroutine1
。所以将被调用。但请注意,存在并发症。例如,
libA.so
可以与-Bsymbolic
链接,这将导致从libA.so< 内部对
subroutine1
的所有调用/code> 绑定到libA.so
本身内的subroutine1
。If you want
subroutine1
fromlibB.so
to be called, then correct link order is-lB -lA
(for Linux and most other UNIX shared library implementations).No: that information is not usually recorded in the executable file. The rule is: whichever shared library defines the
subroutine1
first is the one that will be used.For example, if you link with
-lC -lB -lA
, and at link timelibC.so
does not definesubroutine1
, but later you rebuildlibC.so
(without relinking the executable) so it does, thensubroutine1
fromlibC.so
will be called.However note that there are complications. For example,
libA.so
may be linked with-Bsymbolic
, which will cause all calls tosubroutine1
from withinlibA.so
to bind tosubroutine1
withinlibA.so
itself.