You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无需打开Force 2.0 GUI,能否通过命令提示符编译运行Fortran程序?

Compiling & Running Fortran Programs with Force 2.0 via CMD (No GUI Needed)

Absolutely! You can skip the Force 2.0 graphical interface entirely and compile/run your Fortran code straight from Command Prompt (CMD). Force 2.0 actually bundles the GNU Fortran compiler (gfortran) under the hood, so all the command-line tools you need are already included with your installation.

Here's a straightforward, step-by-step breakdown to get you started:

1. Make Sure the Compiler is Accessible (Set PATH if Needed)

First, confirm your system’s PATH environment variable includes the folder where Force 2.0 stores its gfortran executable. By default, this path is usually:

C:\Program Files\Force 2.0\mingw\bin
  • To check if it’s already configured, open CMD and run:
    gfortran --version
    
    If you see version details pop up, you’re ready to go. If not, you can temporarily add the path for your current CMD session:
    set PATH=%PATH%;C:\Program Files\Force 2.0\mingw\bin
    
    For a permanent fix, add the directory to your system’s PATH via Windows’ Environment Variables settings.

2. Compile Your Fortran Source File

Use the cd command to navigate to the folder where your .f90 (or .f) source code is saved. For example:

cd C:\Users\YourUsername\FortranProjects

Then compile the code with gfortran:

gfortran my_program.f90 -o my_program.exe
  • Replace my_program.f90 with the actual name of your source file
  • The -o my_program.exe flag lets you name the output executable (feel free to use any name you prefer here)

If there are no syntax or logic errors in your code, a new .exe file will appear in the same folder.

3. Run the Compiled Program

Once compilation succeeds, launch the executable directly in CMD:

my_program.exe

You’ll see your Fortran program’s output printed right in the command prompt window.

Quick Troubleshooting Tips

  • If you get a "command not found" error for gfortran, double-check that your PATH is correctly pointing to the Force 2.0 mingw\bin directory.
  • If compilation fails, read the error messages closely—they’ll highlight line numbers and specific issues (like typos or undefined variables) in your code.

内容的提问来源于stack exchange,提问作者Madhurjya Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:52:43