编译.f文件,“对"MAIN_"问题的未定义引用 [英] Compiling .f file, "undefined reference to 'MAIN_' issue

查看:80
本文介绍了编译.f文件,“对"MAIN_"问题的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 g77 来编译.f文件.我尝试使用.cmd批处理文件进行编译(按照g77

I am trying to compile an .f file using g77. I tried to compile it with .cmd batch file (as per one of the ways described in g77 documentation) with the following content (in .cmd file):

g77 -o gtemp.exe gtemp.f
pause

但是当我运行上方的.cmd文件时,出现以下错误消息:对"MAIN_"的未定义引用

But when I run the upper .cmd file, I get the following error message: "undefined reference to 'MAIN_'

为什么会这样?gtemp.f文件与g77.exe文件位于同一文件夹中.谢谢.

Why is this happening? The gtemp.f file is in the same folder as g77.exe file. Thank you.

这是gtemp.f文件的代码:

Here is the code for the gtemp.f file:

      SUBROUTINE GTEMP(DIF,TMIN,TMAX,TAV,TG)                                    GTEMP    2
      DIMENSION AMON(12),TG(12)                                                 GTEMP    3
      DATA AMON / 15.,46.,74.,95.,135.,166.,196.,227.,258.,288.,                GTEMP    4
     1            319.,349. /                                                   GTEMP    5
      DATA P,PI,PO / 8760.,3.14159265,0.6 /                                     GTEMP    6
C                                                                               GTEMP    7
      BETA   = SQRT(PI/(DIF*P))*10.                                             GTEMP    8
      X      = EXP(-BETA)                                                       GTEMP    9
      X2     = X*X                                                              GTEMP   10
      C      = COS(BETA)                                                        GTEMP   11
      S      = SIN(BETA)                                                        GTEMP   12
      Y      = X2 - 2.*X*C + 1.                                                 GTEMP   13
      Y      = Y / (2.*BETA*BETA)                                               GTEMP   14
      GM     = SQRT(Y)                                                          GTEMP   15
      Z      = (1.-X*(C+S)) / (1.-X*(C-S))                                      GTEMP   16
      PHI    = ATAN(Z)                                                          GTEMP   17
      BO     = (TMAX-TMIN)*0.5                                                  GTEMP   18
      DO 40 I=1,12                                                              GTEMP   19
      THETA  = AMON(I)*24.                                                      GTEMP   20
   40 TG(I)  = TAV - BO*COS(2.*(PI/P)*THETA-PO-PHI)*GM + 460.                   GTEMP   21
      RETURN                                                                    GTEMP   22
      END                                                                       GTEMP   23

推荐答案

当编译器找不到主程序时,就会发生此问题.

This problem happens when the compiler cannot find a main program.

按如下所示创建一个主程序

Create a main program as follows

Program Test
Implicit None 

Real :: DIF, TMIN, TMAX, TAV, TG(12) 

Call GTEMP(DIF,TMIN,TMAX,TAV,TG)

Contains

  SUBROUTINE GTEMP(DIF,TMIN,TMAX,TAV,TG)
  ..... 
  END SUBROUTINE GTEMP

End Program Test

这篇关于编译.f文件,“对"MAIN_"问题的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆