admin管理员组

文章数量:1122832

I am trying to link an application compiled with gcc 8.5.0 to c and Fortran libraries compiled with gcc 8.5.0 and gfortran (version unknown) on Oracle Linux (a RedHat derivative). Linking to the gcc compiled library works just fine, so I will omit details. Linking the C application to the Fortran library gives me undefined references, however. The issue seems to be with a trailing/appended underscore in the exported symbols of the Fortran library. I have no control over the Fortran library.

My C code calls the Fortran symbols as so: foo_c_app.exe:

foo_fortran_routine(x, y, z);

If I change the calls to:

foo_fortran_routine_(x, y, z);

Linking works without error. All of the code is considered legacy and worked in the past with simple compiler options. I would like to not change the code to get it to compile and link without error, as was done before, is it possible, if so how?

Also, when I execute nm on the Fortran library, I get:

T foo_fortran_routine_

Thus far, I have tried using gcc and gfortran for linking with various options, but nothing has worked. The only thing that works is adding the trailing underscore to the function calls in the C code, which is not ideal in my opinion.

本文标签: linking gcc compiled c application to c and gfortran librariesStack Overflow