如何以及何时执行静态链接 (MinGW)?

发布于 2024-10-07 02:32:14 字数 675 浏览 3 评论 0原文

将 C++ 应用程序链接到另一个具有 Fortran90 依赖项(MinGW、TDM g++ 和 gfortran)的 C++ 库时,我遇到了很多麻烦。我要么必须使用 gfortran 进行链接,要么应用程序在启动时崩溃(在以 __cxa_get_globals_fast 为键的全局构造函数中)。然而这是不可接受的,我想使用 g++ 进行链接(Qt GUI)。

在我看来,库的依赖项不能与 gcc 静态链接,仅在 main() 可用时才执行链接。为什么?

我猜部分是因为某些初始化的代码必须在 main() 之前插入。

为什么静态链接的应用程序在运行时需要DLL-s,例如mingwm10.dll或pthreadGCE2.dll?为什么这些不能静态链接?

更新:我刚刚找到这些网站:
http://www.deer-run.com/~hal/sol-static .txt
http://www.iecc.com/linker/

I had a lot of pain linking a C++ application to another C++ library with Fortran90 dependencies (MinGW, TDM g++ and gfortran). I either have to use gfortran for linking or the application crashes on startup (in global constructors keyed to __cxa_get_globals_fast). However this is not acceptable, I would like to use g++ for linking (Qt GUI).

It seems to me that the dependencies of the libraries cannot be linked statically with gcc, linking is only performed when main() is available. Why?

I guess partly because code for certain initializations have to be inserted before main().

Why is it that the statically linked application needs DLL-s, such as mingwm10.dll or pthreadGCE2.dll at runtime? Why can't these be statically linked?

UPDATE: I just found these websites:
http://www.deer-run.com/~hal/sol-static.txt
http://www.iecc.com/linker/

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

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

发布评论

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

评论(2

笑看君怀她人 2024-10-14 02:32:14

使用 gfortran 链接和使用 ld/gcc/g++ 链接之间的主要区别在于 gfortran 默认情况下链接标准 fortran 库,而使用另一个链接器则需要手动指定要链接的库。我无法通过快速搜索找到它们,但它应该与 -lgfortran 类似。

此外,gfortran 还有一些特定的初始化例程的说明<如果您的主程序不是用 Fortran 编写的,则需要调用 /a> 才能使某些 Fortran 内在函数起作用。如果您没有调用这些例程,那么这可能会导致崩溃。

The main difference between linking with gfortran and using ld/gcc/g++ to link is that gfortran links the standard fortran libraries by default, whereas with another linker you will need to manually specify the libraries to link. I wasn't able to find them with a quick search, but it should be along the lines of -lgfortran.

Also, gfortran has some specific instructions for initialisation routines that need to be called for certain fortran intrinsics to work if your main program is not written in fortran. If you haven't called these routines then this might cause a crash.

很糊涂小朋友 2024-10-14 02:32:14

为什么静态链接的应用程序在运行时需要DLL,例如mingwm10.dll或pthreadGCE2.dll?为什么这些不能静态链接?

它们可以,但由于动态库的基本优势,不提供静态库版本:可以修复错误而无需重建可执行文件。

Why is it that the statically linked application needs DLL-s, such as mingwm10.dll or pthreadGCE2.dll at runtime? Why can't these be statically linked?

They can, but static library versions are not provided due to the fundamental advantage of dynamic libraries: bugs can be fixed without rebuilding the executables.

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