FreeBSD安装Fortran

2023-12-29
#Unix #FreeBSD #Fortran

1. 说明

FreeBSD 的 Fortran 编译器是 lfortran :

LFortran is a modern open-source (BSD licensed) interactive Fortran compiler built on top of LLVM. It can execute user’s code interactively to allow exploratory work (much like Python, MATLAB or Julia) as well as compile to binaries with the goal to run user’s code on modern architectures such as multi-core CPUs and GPUs.

2. 安装和测试

搜索 Fotran :

sudo pkg search Fortran

cfortran-4.3                   Easy-to-use powerful bridge between C and FORTRAN
fortran-utils-1.1              Tools for use with Fortran code, from 4.4BSD
json-fortran-8.3.0.8           Modern Fortran JSON API
lfortran-0.20.3                Modern interactive Fortran compiler built on top of LLVM
linux-c7-libgfortran-4.8.5_6   Runtime libraries for gfortran (Linux Centos 7.9.2009)
netcdf-fortran-4.6.0           Fortran library for machine-independent, array-oriented data access

安装 lfortran :

sudo pkg install lfortran
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 17 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
    binutils: 2.40_4,1
    dwarfdump: 20161124
    e2fsprogs-libuuid: 1.47.0
    lfortran: 0.20.3
    libedit: 3.1.20221030,1
    libfmt: 9.1.0
    liblz4: 1.9.4,1
    libunwind: 20211201_2
    libzmq4: 4.3.4
    llvm15: 15.0.7_7
    lua53: 5.3.6
    norm: 1.5r6_3
    openpgm: 5.2.122_6
    perl5: 5.34.3_3
    xeus: 3.1.0_1
    xeus-zmq: 1.1.0
    zstd: 1.5.5

Number of packages to be installed: 17

The process will require 1 GiB more space.
26 MiB to be downloaded.

lfortran 的版本:

lfortran --version

lFortran version: 0.20.3
Platform: FreeBSD
Default target: x86_64-portbld-freebsd13.2

lfortran 的帮助说明:

lfortran --help

LFortran: modern interactive LLVM-based Fortran compiler
Usage: lfortran [OPTIONS] [files...] [SUBCOMMAND]

Positionals:
  files TEXT ...         Source files

Options:
  -h,--help              Print this help message and exit
  -S                     Emit assembly, do not assemble or link
  -c                     Compile and assemble, do not link
  -o TEXT                Specify the file to place the output into
  -v                     Be more verbose
  -E                     Preprocess only; do not compile, assemble or link
  -l TEXT ...            Link library option
  -L TEXT ...            Library path option
  -I TEXT ...            Include path
  -J TEXT                Where to save mod files
  -g                     Compile with debugging information
  -D TEXT ...            Define <macro>=<value> (or 1 if <value> omitted)
  --version              Display compiler version information
  -W TEXT ...            Linker flags
  --cpp                  Enable C preprocessing
  --fixed-form           Use fixed form Fortran source parsing
  --fixed-form-infer     Use heuristics to infer if a file is in fixed form
  --no-prescan           Turn off prescan
  --show-prescan         Show tokens for the given file and exit
  --show-tokens          Show tokens for the given file and exit
  --show-ast             Show AST for the given file and exit
  --show-asr             Show ASR for the given file and exit
  --with-intrinsic-mods  Show intrinsic modules in ASR
  --show-ast-f90         Show Fortran from AST for the given file and exit
  --no-color             Turn off colored AST/ASR
  --no-indent            Turn off Indented print ASR/AST
  --tree                 Tree structure print ASR/AST
  --json                 Print ASR/AST Json format
  --visualize            Print ASR/AST Visualization
  --pass TEXT            Apply the ASR pass and show ASR (implies --show-asr)
  --skip-pass TEXT       Skip an ASR pass in default pipeline
  --show-llvm            Show LLVM IR for the given file and exit
  --show-cpp             Show C++ translation source for the given file and exit
  --show-c               Show C translation source for the given file and exit
  --show-asm             Show assembly for the given file and exit
  --show-wat             Show WAT (WebAssembly Text Format) and exit
  --show-julia           Show Julia translation source for the given file and exit
  --show-stacktrace      Show internal stacktrace on compiler errors
  --symtab-only          Only create symbol tables in ASR (skip executable stmt)
  --time-report          Show compilation time report
  --static               Create a static executable
  --no-warnings          Turn off all warnings
  --no-error-banner      Turn off error banner
  --error-format TEXT=human
                         Control how errors are produced (human, short)
  --backend TEXT=llvm    Select a backend (llvm, cpp, x86, wasm)
  --openmp               Enable openmp
  --generate-object-code Generate object code into .o files
  --rtlib                Include the full runtime library in the LLVM output
  --use-loop-variable-after-loop
                         Allow using loop variable after the loop
  --fast                 Best performance (disable strict standard compliance)
  --link-with-gcc        Calls GCC for linking instead of clang
  --target TEXT          Generate code for the given target
  --print-targets        Print the registered targets
  --implicit-typing      Allow implicit typing
  --implicit-interface   Allow implicit interface
  --implicit-argument-casting
                         Allow implicit argument casting
  --print-leading-space  Print leading white space if format is unspecified
  --interactive-parse    Use interactive parse
  --verbose              Print debugging statements
  --dump-all-passes      Apply all the passes and dump the ASR into a file
  --cumulative           Apply all the passes cumulatively till the given pass
  --realloc-lhs          Reallocate left hand side automatically
  --module-mangling      Mangles the module name
  --global-mangling      Mangles all the global symbols
  --intrinsic-mangling   Mangles all the intrinsic symbols
  --all-mangling         Mangles all possible symbols
  --bindc-mangling       Mangles functions with abi bind(c)
  --mangle-underscore    Mangles with underscore
  --run                  Executes the generated binary

Subcommands:
  fmt                    Format Fortran source files.
  kernel                 Run in Jupyter kernel mode.
  mod                    Fortran mod file utilities.
  pywrap                 Python wrapper generator

第一个 helloworld.f90 程序的内容:

program hello_world
        implicit none
        write (*, *) 'Hello World!'
end program hello_world

用 lfortran 编译执行 helloworld.f90 :

lfortran -o helloworld helloworld.f90 && ./helloworld

Hello World!

3. 延伸阅读