I am going to call a C++ function from FORTRAN, for which I am using ISO_C_Binding module. After compaction of the FORTRAN main file and C++ function with commands
gfortran -c mlp8.f90
g++ -开发者_如何学Goc mean_cpp.cc
Which will create the objects files but in the linking phase as suggested by some members I am going to use the commands
g++ mlp8.o mean_cpp.o -o main –lgfortran
I.e. using C++ compiler with linking to FORTRAN libraries but it gives error like
/Cygnus/cygwin-b20/H-i586-cygwin32/i586-win32/bin/ld:
cannot open –lgfortran: No such a file or directory
Collect2:ld return 1 exit status
So I think the main problem is that the g++
linker can not link with the FORTRAN libraries, so may be I need to include some path in the linking option or may be I need to do some setting in the g++
complier, which I don’t know how to do this, so please help to sort out this problem.
You should find file libgfortran.*
(e.g. with locate
of find / -name "libgfortran.*"
; or in windows-way Win+g, F3
or any file manager), record the path where it is and do
g++ mlp8.o mean_cpp.o -o main -LPATH_RECORDED –lgfortran
where PATH_RECORDED is the path.
Try this lib list (got it from my mingw gfortran with -v option)
g++ mlp8.o mean_cpp.o -o main -LPATH_RECORDED –lgfortran -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt
精彩评论