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

Fortran报错“Error: Two main PROGRAMs at (1) and (2)”调试求助

Debugging Fortran's "Two main PROGRAMs at (1) and (2)" Error

Hey there, let's get this sorted out right away: passing arrays as function arguments isn't causing this error—this is strictly a problem with having multiple entry points in your codebase. Here's how to track down and fix the issue:

  • Audit all source files for PROGRAM declarations
    Go through every .f90/.f file in your project and look for lines starting with PROGRAM <program_name>. It's super easy to accidentally leave a stray PROGRAM block in a module or subroutine file—maybe you copied code from a test script or another project and forgot to strip out the main program declaration.

  • Check included files and module dependencies
    If you're using INCLUDE statements or USE to pull in modules, double-check those included/module files. Sometimes a module might have a leftover PROGRAM block from testing, or you might be including a file that defines a main program without realizing it.

  • Validate your compilation command
    Are you compiling multiple source files that each contain their own PROGRAM block? For example, running gfortran main.f90 helper.f90 where helper.f90 also has a PROGRAM statement will trigger this error. Only one file in your compilation set should have a main PROGRAM block—convert any extra ones to SUBROUTINE or FUNCTION (and wrap them in a module if needed).

  • Watch for implicit main programs
    Some Fortran compilers treat the first standalone executable unit (a subroutine/function not wrapped in a module or program) as an implicit main program if there's no explicit PROGRAM block. If you have two such standalone routines, the compiler might interpret both as main programs. Make sure all helper code is either inside a module or explicitly part of your main program's scope.

A quick test: try compiling just your intended main program file in isolation. If that compiles without errors, you know the problem lives in another file you're including or compiling alongside it.

内容的提问来源于stack exchange,提问作者Rik Ghosh

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 10:03:46