在cygwin中使用gfortran构建并将fortran dll链接到fortran代码 [英] Build and link a fortran dll to a fortran code with gfortran in cygwin

查看:638
本文介绍了在cygwin中使用gfortran构建并将fortran dll链接到fortran代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个fortran dll,现在尝试在fortran主程序中使用它.问题是我无法将主程序正确链接到dll.

I built a fortran dll and I try now to use it in a fortran main. The problem is I cannot link correctly the main to the dll.

我在WIndows10上,我使用cygwin的gfortran(cygwin的32位版本,gfortran来自套件i686-w64-mingw32).

I am on WIndows10 and I use gfortran from cygwin (the 32 bit version of cygwin, gfortran comes from the suite i686-w64-mingw32).

这是dll: $更多helloworld.f90

Here is the dll: $ more helloworld.f90

function hello()
integer hello
hello=1
return
end

我这样编译并生成dll:

I complile and generate the dll like this:

gfortran -fno-underscoring  -c helloworld.f90
gfortran -shared -o helloworld.dll  helloworld.o

这是主要的 $ $ usehello.f90

Here is the main $ more usehello.f90

program usehello
integer, external :: hello
integer :: i
i=1
write(*,*) hello(i)
stop
end

编译正常:

i686-w64-mingw32-gfortran.exe -c  -fno-underscoring  usehello.f90

链接失败:

i686-w64-mingw32-gfortran.exe  usehello.o helloworld.dll -o usehello
error while loading shared libraries: libgfortran-5.dll: cannot open shared object file: No such file or directory

但是,我有这个文件:

$ ls -l  /usr/i686-w64-mingw32/sys-root/mingw/bin/libgfortran-5.dll
-rwxr-xr-x 1 UT013536+l-pg164999 UT013536+Aucun 2460672  4 mars  04:46 /usr/i686-w64-mingw32/sys-root/mingw/bin/libgfortran-5.dll

我试图添加--static-libgfortran(我不确信不为dll使用某些静态"东西,但是...): 显然链接正确,但是可执行文件失败:

I have tried to add --static-libgfortran (I wasn't not convinced of using something 'static' for a dll but so...): It links apparently correctly but the executable fails:

$ i686-w64-mingw32-gfortran.exe  usehello.o helloworld.dll -static-libgfortran -o usehello
$ ./usehello
usehello.exe: error while loading shared libraries: libquadmath-0.dll: cannot open shared object file: No such file or directory

听起来好像缺少环境变量,但是我找不到关于这种失败的任何报告.谢谢,以防有人可以帮忙...

Sounds like if an environnement variable was missing but I cannot find any post reporting on this kind of fail. Thanks in case some one can help...

推荐答案

实际上,使用命令i686-w64-mingw32-gfortran.exe的想法不好.

Actually, the idea to use the command i686-w64-mingw32-gfortran.exe is not good...if we simply use gfortran it works fine...

这篇关于在cygwin中使用gfortran构建并将fortran dll链接到fortran代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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