Linking FORTRAN and C++ objects files

為{幸葍}努か 提交于 2019-12-23 04:14:07

问题


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++ -c 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.


回答1:


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


来源:https://stackoverflow.com/questions/7264525/linking-fortran-and-c-objects-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!