链接FORTRAN和C ++对象文件 [英] Linking FORTRAN and C++ objects files

查看:166
本文介绍了链接FORTRAN和C ++对象文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算从FORTRAN调用一个C ++函数,为此我使用ISO_C_Binding模块。使用命令压缩FORTRAN主文件和C ++函数后

  gfortran -c mlp8.f90 

g ++ -c mean_cpp.cc

这将创建对象文件,但在链接阶段,成员我将使用命令

  g ++ mlp8.o mean_cpp.o -o main -lgfortran 

code>

即,使用C ++编译器链接到FORTRAN库,但它会给出错误,如$ / b
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ / $ Cy $ c $ / cygwin -b20 / H-i586-cygwin32 / i586-win32 / bin / ld:
无法打开-lgfortran:没有这样的文件或目录

Collect2:ld返回1退出状态

所以我认为主要的问题是 g ++ 链接器无法链接到FORTRAN库,所以可能是我需要在链接选项中包含一些路径,或者可能需要在 g ++ 编译器中进行一些设置,我不知道如何执行此操作,所以请帮忙解决这个问题。

解决方案

您应该找到 libgfortran。* c $ c> locate find / -namelibgfortran。*;或以windows-way Win + g ,F3 或任何文件管理器),记录它所在的路径并执行

  g ++ mlp8。 o其中,PATH_RECORDED是路径。



试试这个lib列表(使用-v选项从我的mingw gfortran中获得)

  g ++ mlp8.o mean_cpp.o -o main -LPATH_RECORDED -lgfortran -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt 


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.

解决方案

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

这篇关于链接FORTRAN和C ++对象文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆