ifort中linux框上的编译器选项

时间:2012-04-09 14:31:11

标签: linker compiler-errors fortran

我正在使用ifort,当我尝试使用编译器选项编译程序时,我收到链接错误。不过,我已经在一个非常小的简单程序上测试了这些选项,我遇到了同样的问题。

因此我怀疑它与ifort的安装方式或我使用的系统类型有关,但我无法确定。这些程序在没有选项的情况下编译时可以正常编译。我的问题是我做错了是不是在使用编译器选项或编译器选项与我正在使用的系统不兼容时不会出现这些错误。

以下是该程序如何定期编译:

 ifort -free  testrealprint.out testrealprint.f90

以下是如何使用选项编译程序:

    ifort -free  -O2 -stand f03 -check all -traceback -warn all -fstack-protector -    assume protect_parens -implicitnone testrealprint.out testrealprint.f90

这是我用来测试编译器选项的非常简单的代码:

program main 

implicit none

real, dimension(1:3)  :: adremvect
 integer :: j
 character (LEN = 7) :: adremchar, adremcharadj,adremcharadjtrm, adremcharnew 
 adremvect = (/ 2.0, 1.3, 1.0 /)
  do j = 1, 3
        write(adremchar, '(f5.1)') adremvect(j)
        adremcharadj = adjustl(adremchar)
        adremcharadjtrm =  trim(adremcharadj)
         adremcharnew = adremchar(4:)
          print *, adremvect(j), adremcharadj, adremcharadjtrm, adremcharnew
 end do

这是我使用编译器选项时收到的错误消息的一部分:

testrealprint.out: In function `_start':
(.text+0x0): multiple definition of `_start'
 /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib64/crt1.o:(.text+0x0): first     defined here
  testrealprint.out: In function `_fini':
  (.fini+0x0): multiple definition of `_fini'
  /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib64/crti.o:(.fini+0x0): first     defined here
   testrealprint.out:(.rodata+0x0): multiple definition of `_IO_stdin_used'
   /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib64/crt1.o:  (.rodata.cst4+0x0):   first defined here
        testrealprint.out: In function `__data_start':
     (.data+0x0): multiple definition of `__data_start'
   ld: error in testrealprint.out(.eh_frame); no .eh_frame_hdr table will be created.

1 个答案:

答案 0 :(得分:5)

看起来非常像缺少命令行选项来命名编译器发出的可执行文件。我认为你实际上想要这样的东西(注意-o选项):

ifort -free  -O2 -stand f03 -check all -traceback -warn all -fstack-protector -assume protect_parens -implicitnone -o testrealprint.out testrealprint.f90

您看到的错误可能是因为您告诉编译器通过编译testrealprint.f90然后将其与现有可执行文件 testrealprint.out链接来尝试生成可执行文件。这就是您从链接器获取重复符号错误的原因 - 您尝试将现有应用程序链接到当前链接器调用。在搜索路径中没有现有testrealprint.out的情况下尝试编译时,您没有收到文件未找到错误,我感到很惊讶....