在 macOS 中运行 Fortran

在 Mac 中,fortran 被集成在 gcc 中,而 MacOS 本身不提供 gcc 而是 clang,因而可以借助 brew 安装:

$ brew install gcc

以下是 helloworld 程序,保存为 xx.f90

program hello
print *, "Hello World"
end program hello

在 terminal 中运行,与运行 C、C++ 程序非常相似。

$ gfortran xx.f90 -o xx
$ ./xx

保存为文件命名后缀应该是 f90,不是 f,可以看看 stackoverflow上的解释。
f90 给予了更加自由的程序编写格式,fortran 原本的设计目的是为了公式推导科学计算。

如果不安装 fortran 可能会遇到一些问题,例如:

$ pip install pymc
# Error information
    don't know how to compile Fortran code on platform 'posix'
    warning: build_ext: f77_compiler=None is not available.

    building 'pymc.flib' extension
    error: extension 'pymc.flib' has Fortran sources but no Fortran compiler found

例如:

$ easy_install pymc
# Error information
Could not locate executable gfortran
Could not locate executable f95
Could not locate executable f90
Could not locate executable f77
Could not locate executable xlf90
Could not locate executable xlf
Could not locate executable ifort
Could not locate executable ifc
Could not locate executable g77
Could not locate executable g95
Could not locate executable pgfortran
don't know how to compile Fortran code on platform 'posix'
warning: build_ext: f77_compiler=None is not available.

error: Setup script exited with error: extension 'pymc.flib' has Fortran sources but no Fortran compiler found
MAC
本作品采用《CC 协议》,转载必须注明作者和本文链接

不要试图用百米冲刺的方法完成马拉松比赛。

讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!