linux - 是否可以在 Linux 中编译独立的 Fortran 可执行文件?

标签 linux fortran executable

例如,假设我在一台计算机上编写了一个 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/

相关文章:

executable - IDA Pro 和编辑可执行文件

python - cron python 文件在 centos 7 上不起作用

php - 用 php 执行 awk linux 命令

linux - 按bash中的多列排序

c - 在 Linux 模块中包含自定义 header

c - 具有与 MIT Kerberos 兼容的远程构建功能的 IDE

pointers - Fortran 解除分配

可以将文本文档和其他文件打包成 C 可执行文件吗

python - 运行一个可执行文件,等待它产生输出,运行另一个程序

arrays - 在 Fortran 中分配时自动分配数组