How and when is static binding (MinGW) performed?

It was very painful for me to associate a C ++ application with another C ++ library with Fortran90 dependencies (MinGW, TDM g ++, and gfortran). I either have to use gfortran for communication, or application crashes on startup (in global constructors bound to __cxa_get_globals_fast). However, this is unacceptable, I would like to use g ++ for linking (Qt GUI).

It seems to me that the library dependencies cannot be statically linked to gcc, the binding is performed only when main() . Why?

I think, in part because the code for some initializations should be inserted before main ().

Why does a statically linked application need DLL files such as mingwm10.dll or pthreadGCE2.dll at runtime? Why can't they be statically linked?

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

+4
source share
2 answers

The main difference between linking to gfortran and using ld / gcc / g ++ for linking is that gfortran links the standard fortran libraries by default, while with another linker you will need to manually specify the libraries for the link. I could not find them with a quick search, but it should be in the -lgfortran lines.

In addition, gfortran has some special instructions for initialization procedures that must be called in order for certain fortran intrinsics to work if your main program is not written in fortran. If you did not call these routines, it may cause a crash.

+1
source

Why does a statically linked application need DLL files such as mingwm10.dll or pthreadGCE2.dll at runtime? Why can't they be statically linked?

They can, but static versions of the library are not provided due to the fundamental advantage of dynamic libraries: errors can be fixed without re-creating the executable files.

+1
source

All Articles