gfortran:非法预处理器指令&无效的字符/非数字字符编译错误

时间:2012-06-12 18:28:32

标签: compilation preprocessor fortran gfortran directive

所以我正在尝试使用NAS基准测试来对特定的MPI实现进行性能测试。所以我去编译fortran代码,我遇到了障碍。每当我输入此命令进行编译时:

gfortran -O0 -Wall -I/home/stephen/trunk/include -I.  -c ./TestData/common/timers.f

我遇到了这些编译器错误:

Warning: mpif.h:2: Illegal pdreprocessor directive
Warning: mpif.h:3: Illegal preprocessor directive
Warning: mpif.h:4: Illegal preprocessor directive
Warning: mpif.h:5: Illegal preprocessor directive
Warning: mpif.h:6: Illegal preprocessor directive
Warning: mpif.h:7: Illegal preprocessor directive
Warning: mpif.h:8: Illegal preprocessor directive
Warning: mpif.h:9: Illegal preprocessor directive
Warning: mpif.h:12: Illegal preprocessor directive
Warning: mpif.h:13: Illegal preprocessor directive
Warning: mpif.h:14: Illegal preprocessor directive
Warning: mpif.h:2: Illegal preprocessor directive
Warning: mpif.h:3: Illegal preprocessor directive
Warning: mpif.h:4: Illegal preprocessor directive
Warning: mpif.h:5: Illegal preprocessor directive
Warning: mpif.h:6: Illegal preprocessor directive
Warning: mpif.h:7: Illegal preprocessor directive
Warning: mpif.h:8: Illegal preprocessor directive
Warning: mpif.h:9: Illegal preprocessor directive
Warning: mpif.h:12: Illegal preprocessor directive
Warning: mpif.h:13: Illegal preprocessor directive
Warning: mpif.h:14: Illegal preprocessor directive
mpif.h:1.1:
    Included at ./TestData/common/timers.f:30:

/*
 1
Error: Non-numeric character in statement label at (1)
mpif.h:1.2:
    Included at ./TestData/common/timers.f:30:

/*
  1
Error: Invalid character in name at (1)
mpif.h:1.1:
    Included at ./TestData/common/timers.f:50:

/*
 1
Error: Non-numeric character in statement label at (1)
mpif.h:1.2:
    Included at ./TestData/common/timers.f:50:

/*
  1
Error: Invalid character in name at (1)
make: *** [cg] Error 1

这是错误的timers.f代码(第30行和第50行是包含行):

c---------------------------------------------------------------------                                                                                                                                         
c---------------------------------------------------------------------                                                                                                                                         
      subroutine timer_start(n)
c---------------------------------------------------------------------                                                                                                                                         
c---------------------------------------------------------------------                                                                                                                                         
      implicit none
      integer n
      include 'mpif.h'
      double precision start(64), elapsed(64)
      common /tt/ start, elapsed
      start(n) = MPI_Wtime()
      return
      end
c---------------------------------------------------------------------                                                                                                                                         
c---------------------------------------------------------------------                                                                                                                                         
      subroutine timer_stop(n)
c---------------------------------------------------------------------                                                                                                                                         
c---------------------------------------------------------------------                                                                                                                                         
      implicit none
      integer n
      include 'mpif.h'
      double precision start(64), elapsed(64)
      common /tt/ start, elapsed
      double precision t, now
      now = MPI_Wtime()
      t = now - start(n)
      elapsed(n) = elapsed(n) + t
      return
      end

有什么想法吗?我已经尝试过gfortran的各种命令行args尝试让它做不同类型的预处理(大多数这些都是盲目完成的,我承认)。对我来说奇怪的是,编译器错误地在我的代码中没有出现的非数字字符/ *,所以我很丢失。

谢谢!

2 个答案:

答案 0 :(得分:4)

您肯定是以非标准方式编译此代码。使用mpi编译f77或f90代码的常用方法是使用程序 mpif77 mpif90 ,它们围绕用于构建特定版本MPI的编译器。

例如,在我的笔记本电脑上(使用使用gfortran / gcc编译的OpenMPI),命令mpif77大致相当于:

gfortran -I/usr/local/include -L/usr/local/lib -lmpi_f77 -lmpi -lopen-rte -lopen-pal -lutil

(我通过mpif90 -showme获取此信息 - 我不知道该命令行选项是否属于MPI标准的一部分,因此它可能对您不起作用。)

编译你的代码,我会尝试这样的事情:

mpif77 -O0 -Wall -c ./TestData/common/timers.f -o timers.o

由于没有其他文件要包含在内,因此增加编译器包含使用其他-I标记的路径并没有多大意义 - 你只是增加了你不小心发现错误标题的可能性文件;)。

也许在你当前的目录或者/ home / stephen / trunk / include中有一个文件'mpif.h',当它不应该被选中时。 (看起来你可能会看到一个C头,因为/*是C注释的开头 - 虽然我看不出为什么c头文件会被称为'mpif.h'。)。

答案 1 :(得分:0)

我同意您应该使用mpif77或mpif90链接到正确的库。如果gfortran不喜欢预处理器宏,则应该尝试-cpp编译器选项。