在cygwin中使用gfortran构建fortran dll并将其链接到fortran代码

在cygwin中使用gfortran构建fortran dll并将其链接到fortran代码,dll,linker,fortran,cygwin,mingw32,Dll,Linker,Fortran,Cygwin,Mingw32,我构建了一个fortran dll,现在我尝试在fortran main中使用它。问题是我无法将main正确链接到dll 我在WIndows10上,我使用cygwin的gfortran。在cygwin的32位版本中,gfortran来自i686-w64-mingw32套件 以下是dll: $more helloworld.f90 function hello() integer hello hello=1 return end 我编译并生成如下dll: gfortran -fno-unders

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

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

以下是dll: $more helloworld.f90

function hello()
integer hello
hello=1
return
end
我编译并生成如下dll:

gfortran -fno-underscoring  -c helloworld.f90
gfortran -shared -o helloworld.dll  helloworld.o
这是主要的 $more useholl.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中使用“static”的东西,但是…: 它显然链接正确,但可执行文件失败:

$ 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

听起来好像缺少环境变量,但我找不到任何关于此类失败的后期报告。如果有人能帮上忙,那就谢谢了…

实际上,使用命令i686-w64-mingw32-gfortran.exe的想法并不好…如果我们只使用gfortran,效果会很好