7

I am trying to link on Windows a Fortran code with C++. The Fortran code is compiled with gfortran from MinGW, and the other C++ parts are being compiled with MSVC.

The problem is that the linker generates the following error message:

libgfortran.a(read.o) : error LNK2016: Absolute symbol '_strtoflt128' used as target of REL32 relocation

With the Intel fortran compiler it works.

Tools:

GNU Fortran 6.3.0

MSVC 2013

I used the CMake generated Visual Studio project, which automatically invokes the Microsoft linker. The linker arguments(cleaned):

/MANIFEST /NXCOMPAT /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" "libgfortran.a" "libmingwex.a" "libmingw32.a" "libquadmath.a" "libgcc_s.a" "libgcc.a" "libgcc_eh.a" /MACHINE:X86 /SAFESEH:NO /INCREMENTAL:NO /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1 /machine:X86 /NODEFAULTLIB:"libcpmt.lib"

I tested also on 64 bit and it generates the same error.

  • 2
    Can you provide a [mcve]? – Rodrigo Rodrigues Aug 18 '18 at 15:13
  • Are you sure it's a good idea to mix build toolchains? Any reason not to build the *C++* code via *g++*? Check https://stackoverflow.com/questions/45340527/how-to-circumvent-windows-universal-crt-headers-dependency-on-vcruntime-h/50838055#50838055 (the 2nd part that contains compiler outputs some mix). – CristiFati Aug 22 '18 at 22:28
  • This happens when building code for both *Debug* and *Release*? What about turning off *Whole Program Optimization* (https://msdn.microsoft.com/en-us/library/0zza0de8.aspx) ? – CristiFati Aug 22 '18 at 22:47
  • Any chance to get the *Fortran* code (and the compiler(s) flags)? – CristiFati Aug 23 '18 at 16:59
  • 1
    `strtoflt128` is used to convert a string to a `REAL(16)` entity (i.e., quad precision). You likely need to link in -lquadmath. – steve Feb 01 '21 at 19:20

0 Answers0