Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29267 Discussions

ifort doesn't regonize the gfortran syntax `_gfortran_st_open'??

rolyluoli
Beginner
1,824 Views
Hi,
I have a main fortran code which needs to call other fortran subroutines defined in other files, for example, in the main.for, a subroutine func() is called, and func() is defined in func.for.
for some reason that I need to compile func.for by gfortran, but to compile main.for by ifort,
gfortran -c func.for
ifort-w -o main main.for func.o
However, this manner returns compile error like this:
func.for:(.text+0x1c6): undefined reference to `_gfortran_st_open'
It seems that the ifort compiler does not regonize the gfortransyntax, should I add any options to ifort?
0 Kudos
3 Replies
mecej4
Honored Contributor III
1,823 Views
This is not a compile time error: undefined reference. It is a link-time error. In fact, the message contains func.for (.text+0x...). That is a telltale sign of a linker error, since it is telling you the offset in 'hex of the reference to the unsatisfied external symbol.

Since you compiled func.for using Gfortran, func.o contains references to the Gfortran runtime libraries. Similarly, main.o will contain references to the IFort runtime libraries. Since you used Ifort to drive the linking, you have to list the Gfortran runtime library in the command, e.g. (check which version and library you have in your installation)

$ ifort -w -o main main.for func.o -L -lgfortran

Similarly, if you use Gfortran to drive the linking, you would have to list the Intel Fortran library location and libraries using the -L and -l options.

0 Kudos
rolyluoli
Beginner
1,823 Views
Thank you, it's fixed
0 Kudos
TimP
Honored Contributor III
1,823 Views
There's no guarantee that combinations of ifort and gfortran compilation will work, or continue to work, as there may be conflicts between the run-time libraries.
0 Kudos
Reply