【发布时间】:2020-04-16 13:18:42
【问题描述】:
我构建了一个 fortran dll,现在我尝试在 fortran 主程序中使用它。问题是我无法正确地将 main 链接到 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
这里是主要的 $ 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 使用“静态”的东西,但是......): 它显然正确链接,但可执行文件失败:
$ 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
听起来好像缺少环境变量,但我找不到任何关于这种失败的帖子报告。万一有人可以提供帮助,谢谢...
【问题讨论】:
标签: dll linker fortran cygwin mingw32