gpt4 book ai didi

compiler-errors - gfortran : compile source codes from hierarchically dependent subroutine files

转载 作者:行者123 更新时间:2023-12-02 10:51:57 24 4
gpt4 key购买 nike

我想编译main.f90,它取决于单独文件中的三个子例程。对于第三个子例程,它还具有三个sub_subroutine。

  • sub1.f
  • sub2.f
  • sub3_main.f sub3_sub1.f sub3_sub2.f sub3_sub3.f

  • 运行以下代码将产生如下所示的长错误消息。
    gfortran main.f90 sub1.f sub2.f sub3_main.f sub3_sub1.f sub3_sub2.f sub3_sub3.f -o- test.exe
    我搜索后发现,我可能需要标记 -c,但是我不确定编译的顺序以及如何将目标文件链接到独立程序中。或与此问题有关: how to compile multi-folder Fortran Project having interfaces, modules and subroutines

    提前致谢!
    test.exe: In function `_fini':
    (.fini+0x0): multiple definition of `_fini'
    /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o:(.fini+0x0): first defined here
    test.exe: In function `__data_start':
    (.data+0x0): multiple definition of `__data_start'
    /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.data+0x0): first defined here
    test.exe: In function `__data_start':
    (.data+0x4): multiple definition of `__dso_handle'
    /usr/lib/gcc/i686-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here
    test.exe:(.rodata+0x4): multiple definition of `_IO_stdin_used'
    /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
    test.exe: In function `_start':
    (.text+0x0): multiple definition of `_start'
    /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.text+0x0): first defined here
    test.exe:(.rodata+0x0): multiple definition of `_fp_hw'
    /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.rodata+0x0): first defined here
    test.exe: In function `main':
    (.text+0x399): multiple definition of `main'
    /tmp/ccwQ3UVQ.o:main.f90:(.text+0x20ee): first defined here
    test.exe: In function `_init':
    (.init+0x0): multiple definition of `_init'
    /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o:(.init+0x0): first defined here
    /usr/lib/gcc/i686-linux-gnu/4.6/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
    test.exe:(.dtors+0x4): first defined here
    /usr/bin/ld: error in test.exe(.eh_frame); no .eh_frame_hdr table will be created.
    collect2: ld returned 1 exit status

    最佳答案

    您应该能够执行以下任一操作:

    gfortran -c sub1.f
    gfortran -c sub2.f
    gfortran -c sub3_main.f sub3_sub1.f sub3_sub2.f sub3_sub3.f
    gfortran sub1.o sub2.o sub3_main.o sub3_sub1.o sub3_sub2.o sub3_sub3.o main.f90 -o text.exe

    要么
    gfortran sub1.f sub2.f sub3_main.f sub3_sub1.f sub3_sub2.f sub3_sub3.f main.f90 -o text.exe

    您应该只有一个程序和任意数量的处理程序(子例程和函数)。上面假设sub3_main是一个过程,并且您的程序位于main.f90中。

    关于compiler-errors - gfortran : compile source codes from hierarchically dependent subroutine files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19750117/

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