gpt4 book ai didi

linker - ifort在Linux上的编译器选项

转载 作者:行者123 更新时间:2023-12-02 10:49:29 26 4
gpt4 key购买 nike

我正在使用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.

最佳答案

看起来非常像您缺少用于命名编译器发出的可执行文件的命令行选项。我假设您实际上想要这样的东西(请注意-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的情况下尝试编译时没有得到未找到文件错误...。

关于linker - ifort在Linux上的编译器选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10074754/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com