我建立了一个fortran dll,现在尝试在fortran主程序中使用它。问题是我无法正确将主链接链接到dll。
[我在WIndows10上,我使用cygwin的gfortran(cygwin的32位版本,gfortran来自套件i686-w64-mingw32)。
这是dll:$更多helloworld.f90
function hello()
integer hello
hello=1
return
end
我按照这样生成并生成dll:
gfortran -fno-underscoring -c helloworld.f90
gfortran -shared -o helloworld.dll helloworld.o
这里是主要$ $ 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使用某些“静态”功能,但...):它显然链接正确,但是可执行文件失败:
$ 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,它就可以正常工作...