2012-04-09 57 views
0

我使用ifort,并且在尝试编译带编译器选项的程序时出现链接错误。尽管如此,我已经在一个非常小的简单程序上测试了这些选项,我也遇到了同样的问题。在ifort的linux上的编译选项

因此,我怀疑它与安装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 

这里是我收到的错误消息的一部分,当我使用th e编译器选项:

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. 
+0

您是否试图让编译器命名最终的可执行文件为'testrealprint.out '? – talonmies 2012-04-09 14:36:13

+0

是的,我很努力。 – 2012-04-09 14:45:18

回答

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的编译尝试进行编译时,我感到非常惊讶......

+0

是的,似乎这样做。我没有找到文件未找到错误的原因是因为我已经有了我的目录中的默认版本的测试版本。所以你的答案在这点上非常有意义。 – 2012-04-09 14:52:38

+1

@JourdanGold:如果这个答案解决了你的问题,或许你会如此热情以至于[接受它](http://meta.stackexchange.com/q/5234/163653)? – talonmies 2012-04-11 07:46:29