例如,假设我在一台计算机上编写了一个 Fortran 程序,并想在另一台可能没有所需库和/或具有不同编译器(甚至更好,根本没有 Fortran 编译器)的计算机上运行它。是否可以创建一个包含所有依赖项的可执行文件?
我在 Fedora 26 中使用 gfortran (7.2.1),有时在我的代码中使用 LAPACK 例程。
在程序中使用-static
选项
program main
write (*,*) 'Hello'
end
我得到输出
gfortran -static a.f90
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
gfortran -static-libgfortran a.f90
没有错误
最佳答案
在 Fedora 中,gcc 默认不附带静态库。
您需要安装包 glibc-static
才能使 -static
选项正常工作,如 related question 中所暗示.
请注意,-static-libgfortran
只会对 libgfortran
库进行静态链接,并且您还必须拥有依赖项的静态版本。
关于linux - 是否可以在 Linux 中编译独立的 Fortran 可执行文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48580455/