• C语言:详解gcc驱动程序完成编译、汇编、链接的过程


    相关阅读

    C语言icon-default.png?t=N7T8https://blog.csdn.net/weixin_45791458/category_12423166.html?spm=1001.2014.3001.5482


            gcc是一个命令,严格意义上说,它只是一个驱动程序,而不是一个编译器。gcc负责调用GNU工具链中的预处理器、编译器、汇编器、链接器等工具,通过传递不同的选项给gcc命令,可以让其只完成某些步骤,比如下面的命令,用于只对源文件进行预处理。

    gcc -E test.c

            实际上,gcc命令的参数不仅可以是C语言源文件(.c后缀),也可以是C++语言(.cc、.cpp、.c++、.CPP等后缀), 还可以是fortran语言(.f、.for、.f90、.f95等后缀),ada语言(.adb、.adb后缀)等。

            具体支持的语言后缀,可以在gcc命令的源代码中找到,如下所示(也可以使用man命令在gcc的手册中找到)。

    1. 1409 static const struct compiler default_compilers[] =
    2. 1410 {
    3. 1411 /* Add lists of suffixes of known languages here. If those languages
    4. 1412 were not present when we built the driver, we will hit these copies
    5. 1413 and be given a more meaningful error than "file not used since
    6. 1414 linking is not done". */
    7. 1415 {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0},
    8. 1416 {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0},
    9. 1417 {".mii", "#Objective-C++", 0, 0, 0},
    10. 1418 {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0},
    11. 1419 {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0},
    12. 1420 {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0},
    13. 1421 {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0},
    14. 1422 {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0},
    15. 1423 {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0},
    16. 1424 {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0},
    17. 1425 {".ftn", "#Fortran", 0, 0, 0}, {".FTN", "#Fortran", 0, 0, 0},
    18. 1426 {".fpp", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0},
    19. 1427 {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0},
    20. 1428 {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0},
    21. 1429 {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0},
    22. 1430 {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0},
    23. 1431 {".r", "#Ratfor", 0, 0, 0},
    24. 1432 {".go", "#Go", 0, 1, 0},
    25. 1433 {".d", "#D", 0, 1, 0}, {".dd", "#D", 0, 1, 0}, {".di", "#D", 0, 1, 0},
    26. 1434 /* Next come the entries for C. */
    27. 1435 {".c", "@c", 0, 0, 1},
    28. 1436 {"@c",
    29. 1437 /* cc1 has an integrated ISO C preprocessor. We should invoke the
    30. 1438 external preprocessor if -save-temps is given. */
    31. 1439 "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
    32. 1440 %{!E:%{!M:%{!MM:\
    33. 1441 %{traditional:\
    34. 1442 %eGNU C no longer supports -traditional without -E}\
    35. 1443 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
    36. 1444 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
    37. 1445 cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
    38. 1446 %(cc1_options)}\
    39. 1447 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
    40. 1448 cc1 %(cpp_unique_options) %(cc1_options)}}}\
    41. 1449 %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 1},
    42. 1450 {"-",
    43. 1451 "%{!E:%e-E or -x required when input is from standard input}\
    44. 1452 %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0},
    45. 1453 {".h", "@c-header", 0, 0, 0},
    46. 1454 {"@c-header",
    47. 1455 /* cc1 has an integrated ISO C preprocessor. We should invoke the
    48. 1456 external preprocessor if -save-temps is given. */
    49. 1457 "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
    50. 1458 %{!E:%{!M:%{!MM:\
    51. 1459 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
    52. 1460 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
    53. 1461 cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
    54. 1462 %(cc1_options)\
    55. 1463 %{!fsyntax-only:%{!S:-o %g.s} \
    56. 1464 %{!fdump-ada-spec*:%{!o*:--output-pch=%i.gch}\
    57. 1465 %W{o*:--output-pch=%*}}%V}}\
    58. 1466 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
    59. 1467 cc1 %(cpp_unique_options) %(cc1_options)\
    60. 1468 %{!fsyntax-only:%{!S:-o %g.s} \
    61. 1469 %{!fdump-ada-spec*:%{!o*:--output-pch=%i.gch}\
    62. 1470 %W{o*:--output-pch=%*}}%V}}}}}}}", 0, 0, 0},
    63. 1471 {".i", "@cpp-output", 0, 0, 0},
    64. 1472 {"@cpp-output",
    65. 1473 "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0},
    66. 1474 {".s", "@assembler", 0, 0, 0},
    67. 1475 {"@assembler",
    68. 1476 "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 0, 0},
    69. 1477 {".sx", "@assembler-with-cpp", 0, 0, 0},
    70. 1478 {".S", "@assembler-with-cpp", 0, 0, 0},
    71. 1479 {"@assembler-with-cpp",
    72. 1480 #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
    73. 1481 "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
    74. 1482 %{E|M|MM:%(cpp_debug_options)}\
    75. 1483 %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
    76. 1484 as %(asm_debug) %(asm_options) %|.s %A }}}}"
    77. 1485 #else
    78. 1486 "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
    79. 1487 %{E|M|MM:%(cpp_debug_options)}\
    80. 1488 %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
    81. 1489 as %(asm_debug) %(asm_options) %m.s %A }}}}"
    82. 1490 #endif
    83. 1491 , 0, 0, 0},
    84. 1492
    85. 1493 #include "specs.h"
    86. 1494 /* Mark end of table. */
    87. 1495 {0, 0, 0, 0, 0}
    88. 1496 };

             因为gcc命令使用后缀识别源代码,从而调用不同的工具,所以尝试向gcc命令传递一个没有后缀的文本文件是会报错的,即使文本文件的内容确实是源代码,如下所示。

    1. $ gcc test
    2. test: file not recognized: File format not recognized
    3. collect2: error: ld returned 1 exit status

            下面我们以C语言举例,了解gcc命令是如何处理C源代码文件的。

    1. // test.c
    2. #define TT 1
    3. int main()
    4. {
    5. int a=TT;
    6. }

            向gcc命令传递-v选项,可以让其打印其在执行期间调用的所有工具,如下所示。

    1. $ gcc -v test.c -o test
    2. Using built-in specs.
    3. COLLECT_GCC=gcc
    4. COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
    5. Target: x86_64-redhat-linux
    6. Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
    7. Thread model: posix
    8. gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
    9. COLLECT_GCC_OPTIONS='-v' '-o' 'test' '-mtune=generic' '-march=x86-64'
    10. /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1 -quiet -v test.c -quiet -dumpbase test.c -mtune=generic -march=x86-64 -auxbase test -version -o /tmp/ccifUeJP.s
    11. GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux)
    12. compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-39), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
    13. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    14. ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include-fixed"
    15. ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/include"
    16. #include "..." search starts here:
    17. #include <...> search starts here:
    18. /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include
    19. /usr/local/include
    20. /usr/include
    21. End of search list.
    22. GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux)
    23. compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-39), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
    24. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    25. Compiler executable checksum: d8f4c208bcaf7e279b70f7290eda3265
    26. COLLECT_GCC_OPTIONS='-v' '-o' 'test' '-mtune=generic' '-march=x86-64'
    27. as -v --64 -o /tmp/cceJQa5q.o /tmp/ccifUeJP.s
    28. GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-43.base.el7
    29. COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/
    30. LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/
    31. COLLECT_GCC_OPTIONS='-v' '-o' 'test' '-mtune=generic' '-march=x86-64'
    32. /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. /tmp/cceJQa5q.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o

            可以从上面的输出信息中注意到,gcc命令调用了cc1命令,这才是真正意义上的c编译器。

    /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1 -quiet -v test.c -quiet -dumpbase test.c -mtune=generic -march=x86-64 -auxbase test -version -o /tmp/ccifUeJP.s

            细心的你可能会发现,gcc命令并没有调用cpp(c preprocessor,C预处理器),这是因为这部分功能已经被整合进cc1命令中了。cc1命令编译的输出结果是一个汇编文件,保存为/tmp/ccifUeJP.s,因为它只是一个中间结果。

            下面gcc命令又调用了as命令,这是一个汇编器,输出结果是一个.o后缀的目标文件/tmp/cceJQa5q.o,与上面的汇编文件一样,它也是一个中间结果。

    as -v --64 -o /tmp/cceJQa5q.o /tmp/ccifUeJP.s

            最后,gcc命令调用了collect2命令,这是链接器ld的一个封装,用于链接所有的目标文件,并生成最终的可执行文件test,这是我们最开始传递给gcc命令的参数。

     /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. /tmp/cceJQa5q.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o

            既然gcc命令可以处理不同语言的源代码,那为什么要针对C++语言推出g++驱动程序,对于fortran语言推出gfortran驱动程序,对于ada语言推出gnat驱动程序呢?下面以fortran语言举例说明。

    1. ! add_numbers.f90
    2. program AddNumbers
    3. implicit none
    4. integer :: number1, number2, sum
    5. ! 用户输入两个整数
    6. print *, 'Enter two integers:'
    7. read *, number1, number2
    8. ! 计算两个数的和
    9. sum = number1 + number2
    10. ! 打印结果
    11. print *, 'The sum of ', number1, ' and ', number2, ' is ', sum
    12. end program AddNumbers

            下面直接使用gcc命令编译它,输出结果如下所示。 

    1. $ gcc -v add_numbers.f90 -o add_numbers
    2. Using built-in specs.
    3. COLLECT_GCC=gcc
    4. COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
    5. Target: x86_64-redhat-linux
    6. Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
    7. Thread model: posix
    8. gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
    9. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-64'
    10. /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/f951 add_numbers.f90 -quiet -dumpbase add_numbers.f90 -mtune=generic -march=x86-64 -auxbase add_numbers -version -fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/4.8.5/finclude -o /tmp/ccQACj24.s
    11. GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux)
    12. compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-39), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
    13. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    14. GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux)
    15. compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-39), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
    16. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    17. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-64'
    18. as -v --64 -o /tmp/cctgPTMM.o /tmp/ccQACj24.s
    19. GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-43.base.el7
    20. COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/
    21. LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/
    22. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-64'
    23. /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o add_numbers /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. /tmp/cctgPTMM.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
    24. /tmp/cctgPTMM.o: In function `MAIN__':
    25. add_numbers.f90:(.text+0x3f): undefined reference to `_gfortran_st_write'
    26. add_numbers.f90:(.text+0x58): undefined reference to `_gfortran_transfer_character_write'
    27. add_numbers.f90:(.text+0x67): undefined reference to `_gfortran_st_write_done'
    28. add_numbers.f90:(.text+0x9f): undefined reference to `_gfortran_st_read'
    29. add_numbers.f90:(.text+0xba): undefined reference to `_gfortran_transfer_integer'
    30. add_numbers.f90:(.text+0xd5): undefined reference to `_gfortran_transfer_integer'
    31. add_numbers.f90:(.text+0xe4): undefined reference to `_gfortran_st_read_done'
    32. add_numbers.f90:(.text+0x127): undefined reference to `_gfortran_st_write'
    33. add_numbers.f90:(.text+0x140): undefined reference to `_gfortran_transfer_character_write'
    34. add_numbers.f90:(.text+0x15b): undefined reference to `_gfortran_transfer_integer_write'
    35. add_numbers.f90:(.text+0x174): undefined reference to `_gfortran_transfer_character_write'
    36. add_numbers.f90:(.text+0x18f): undefined reference to `_gfortran_transfer_integer_write'
    37. add_numbers.f90:(.text+0x1a8): undefined reference to `_gfortran_transfer_character_write'
    38. add_numbers.f90:(.text+0x1c3): undefined reference to `_gfortran_transfer_integer_write'
    39. add_numbers.f90:(.text+0x1d2): undefined reference to `_gfortran_st_write_done'
    40. /tmp/cctgPTMM.o: In function `main':
    41. add_numbers.f90:(.text+0x1f4): undefined reference to `_gfortran_set_args'
    42. add_numbers.f90:(.text+0x203): undefined reference to `_gfortran_set_options'
    43. collect2: error: ld returned 1 exit status

            从上面的输出中可以看出,在对fortran文件进行预处理、汇编、编译、链接的过程中,gcc命令调用了f951编译器,as汇编器和collect2链接器,但是在最后的链接阶段却报错了,错误原因是ld找不到Fortran运行时库中的一些必要函数,如_gfortran_st_write等。

            这可以通过向gcc命令传递一些选项来解决,如下所示。

    1. $ gcc -v add_numbers.f90 -lgfortran -o add_numbers
    2. Using built-in specs.
    3. COLLECT_GCC=gcc
    4. COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
    5. Target: x86_64-redhat-linux
    6. Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
    7. Thread model: posix
    8. gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
    9. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-64'
    10. /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/f951 add_numbers.f90 -quiet -dumpbase add_numbers.f90 -mtune=generic -march=x86-64 -auxbase add_numbers -version -fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/4.8.5/finclude -o /tmp/cc4GFhEz.s
    11. GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux)
    12. compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-39), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
    13. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    14. GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux)
    15. compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-39), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
    16. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    17. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-64'
    18. as -v --64 -o /tmp/ccS7OrZX.o /tmp/cc4GFhEz.s
    19. GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-43.base.el7
    20. COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/
    21. LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/
    22. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-64'
    23. /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o add_numbers /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. /tmp/ccS7OrZX.o -lgfortran -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
    24. $ ./add_numbers
    25. Enter two integers:
    26. 1
    27. 2
    28. The sum of 1 and 2 is 3

            如果使用gfortran命令,则无需添加选项,如下所示。

    1. $ gfortran -v add_numbers.f90 -o add_numbers
    2. Driving: gfortran -v add_numbers.f90 -o add_numbers -l gfortran -l m -shared-libgcc
    3. Using built-in specs.
    4. COLLECT_GCC=gfortran
    5. COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
    6. Target: x86_64-redhat-linux
    7. Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
    8. Thread model: posix
    9. gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
    10. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
    11. /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/f951 add_numbers.f90 -quiet -dumpbase add_numbers.f90 -mtune=generic -march=x86-64 -auxbase add_numbers -version -fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/4.8.5/finclude -o /tmp/ccOxqcS0.s
    12. GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux)
    13. compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-39), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
    14. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    15. GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux)
    16. compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-39), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
    17. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    18. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
    19. as -v --64 -o /tmp/cc4yjj1R.o /tmp/ccOxqcS0.s
    20. GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-43.base.el7
    21. Reading specs from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgfortran.spec
    22. rename spec lib to liborig
    23. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
    24. COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/
    25. LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/
    26. COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
    27. /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o add_numbers /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. /tmp/cc4yjj1R.o -lgfortran -lm -lgcc_s -lgcc -lquadmath -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
  • 相关阅读:
    k8s分布式图床(k8s,metricsapi,vue3+ts)
    USB转IIC I2C SPI UART适配器模块可编程开发板应用工业数字接口转换
    力扣 剑指 Offer 51. 数组中的逆序对
    AI Agent涌向移动终端,手机智能体开启跨端跨应用业务连接新场景
    xbox game bar无法打开/安装怎么办?
    基于SVM+TensorFlow+Django的酒店评论打分智能推荐系统——机器学习算法应用(含python工程源码)+数据集+模型(二)
    Redis简介+基础知识+五大基本数据类型+三大特殊数据类型基本使用+Redis到底是单线程还是多线程?
    electron+vue3全家桶+vite项目搭建【28】封装窗口工具类【2】窗口组,维护窗口关系
    基于XML方式的Bean的配置概述
    调用华为API实现身份证识别
  • 原文地址:https://blog.csdn.net/weixin_45791458/article/details/139505557