首页 > 解决方案 > 运行简单的 hello_world 程序时出错

问题描述

我需要下载 Fortran 来完成我的项目。我曾尝试关注 youtube 上的视频(https://www.youtube.com/watch?v=HakTEhU3Q9U),但最后我得到了一个错误。我无法编译一个简单的“hello_world”程序。

我是编程新手,所以我不熟悉计算术语。我已经下载了 java、Eclipse 和 Fortran。当我打开 Eclipse 并尝试编译一个简单的程序时,我得到一个错误。

make all 
Building file: ../helloFortran.f95
/bin/sh: gfortran: command not found
Invoking: GNU Fortran Compiler
gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -o "helloFortran.o" "../helloFortran.f95"
make: *** [helloFortran.o] Error 127
"make all" terminated with exit code 2. Build might be incomplete.

17:00:47 Build Failed. 2 errors, 0 warnings. (took 94ms)

我要运行的程序就是这个。

    program helloFortran
    implicit none
    print*, "Fortran is great"
end program helloFortran

我还有一个文本文件,我不知道它是做什么用的。

#!/bin/bash
PATH=$PATH:/usr/local/gfortran/bin
$HOME/eclipse/parallel-2018-12/Eclipse.app/Contents/MacOS/
eclipse -data $HOME/documents/workspace

标签: fortran

解决方案


确保文件EclipseFortran.sh包含

#!/bin/bash
PATH=$PATH:/usr/local/gfortran/bin $HOME/eclipse/parallel-2018-12/Eclipse.app/Contents/MacOS/eclipse -data $HOME/documents/workspace

PATH 行是单行,最多workspace. 然后,输入

bash EclipseFortran.sh

这应该会在知道 gfortran 位置的情况下启动 eclipse。

以这种方式设置环境有点不寻常。您可以在 Mac OS 上为 GUI 应用程序定义环境变量。我没有使用 Mac OS,所以我可以建议查看https://stackoverflow.com/a/3756674/3327666

launchctl setenv PATH $PATH:/usr/local/gfortran/bin

推荐阅读