http://www.physiology.wisc.edu/comp/docs/notes/not017.html
http://www.math.utah.edu/software/c-with-fortran.html
All individual sources should be compiled into object files by using the "-c" compiler option. Here is how to link these ".o" files. I assume that the main program is in C and a few Fortran subroutines are called.
In gcc-4.0:
".o" from Fortran code is treated the same as those from C++ code. So just use the normal link command:
g++ $(C_FLAGS) $(COBJS) $(FOBJS) $(LIBS) -o $(EXE)
In gcc-3.0:
Same as the 4.0 version, but the code must be linked against libg2c:
g++ $(C_FLAGS) $(COBJS) $(FOBJS) $(LIBS) -lg2c -o $(EXE)
In icc:
Fortran compiler, rather than c++ compiler must be used. The option "-nofor_main" tells the compiler that there is no Fortran main subroutine; "-cxxlib" means to link to the C++ libraries.
ifort -nofor_main -cxxlib $(COBJS) $(FOBJS) $(LIBS) -o $(EXE)
No comments:
Post a Comment