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

发布时间:2026/10/27 18:19:37
C语言:详解gcc驱动程序完成编译、汇编、链接的过程 相关阅读C语言https://blog.csdn.net/weixin_45791458/category_12423166.html?spm1001.2014.3001.5482gcc是一个命令严格意义上说它只是一个驱动程序而不是一个编译器。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的手册中找到。1409 static const struct compiler default_compilers[] 1410 { 1411 /* Add lists of suffixes of known languages here. If those languages 1412 were not present when we built the driver, we will hit these copies 1413 and be given a more meaningful error than file not used since 1414 linking is not done. */ 1415 {.m, #Objective-C, 0, 0, 0}, {.mi, #Objective-C, 0, 0, 0}, 1416 {.mm, #Objective-C, 0, 0, 0}, {.M, #Objective-C, 0, 0, 0}, 1417 {.mii, #Objective-C, 0, 0, 0}, 1418 {.cc, #C, 0, 0, 0}, {.cxx, #C, 0, 0, 0}, 1419 {.cpp, #C, 0, 0, 0}, {.cp, #C, 0, 0, 0}, 1420 {.c, #C, 0, 0, 0}, {.C, #C, 0, 0, 0}, 1421 {.CPP, #C, 0, 0, 0}, {.ii, #C, 0, 0, 0}, 1422 {.ads, #Ada, 0, 0, 0}, {.adb, #Ada, 0, 0, 0}, 1423 {.f, #Fortran, 0, 0, 0}, {.F, #Fortran, 0, 0, 0}, 1424 {.for, #Fortran, 0, 0, 0}, {.FOR, #Fortran, 0, 0, 0}, 1425 {.ftn, #Fortran, 0, 0, 0}, {.FTN, #Fortran, 0, 0, 0}, 1426 {.fpp, #Fortran, 0, 0, 0}, {.FPP, #Fortran, 0, 0, 0}, 1427 {.f90, #Fortran, 0, 0, 0}, {.F90, #Fortran, 0, 0, 0}, 1428 {.f95, #Fortran, 0, 0, 0}, {.F95, #Fortran, 0, 0, 0}, 1429 {.f03, #Fortran, 0, 0, 0}, {.F03, #Fortran, 0, 0, 0}, 1430 {.f08, #Fortran, 0, 0, 0}, {.F08, #Fortran, 0, 0, 0}, 1431 {.r, #Ratfor, 0, 0, 0}, 1432 {.go, #Go, 0, 1, 0}, 1433 {.d, #D, 0, 1, 0}, {.dd, #D, 0, 1, 0}, {.di, #D, 0, 1, 0}, 1434 /* Next come the entries for C. */ 1435 {.c, c, 0, 0, 1}, 1436 {c, 1437 /* cc1 has an integrated ISO C preprocessor. We should invoke the 1438 external preprocessor if -save-temps is given. */ 1439 %{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ 1440 %{!E:%{!M:%{!MM:\ 1441 %{traditional:\ 1442 %eGNU C no longer supports -traditional without -E}\ 1443 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ 1444 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ 1445 cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ 1446 %(cc1_options)}\ 1447 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ 1448 cc1 %(cpp_unique_options) %(cc1_options)}}}\ 1449 %{!fsyntax-only:%(invoke_as)}}}}, 0, 0, 1}, 1450 {-, 1451 %{!E:%e-E or -x required when input is from standard input}\ 1452 %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options), 0, 0, 0}, 1453 {.h, c-header, 0, 0, 0}, 1454 {c-header, 1455 /* cc1 has an integrated ISO C preprocessor. We should invoke the 1456 external preprocessor if -save-temps is given. */ 1457 %{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ 1458 %{!E:%{!M:%{!MM:\ 1459 %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ 1460 %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ 1461 cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ 1462 %(cc1_options)\ 1463 %{!fsyntax-only:%{!S:-o %g.s} \ 1464 %{!fdump-ada-spec*:%{!o*:--output-pch%i.gch}\ 1465 %W{o*:--output-pch%*}}%V}}\ 1466 %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ 1467 cc1 %(cpp_unique_options) %(cc1_options)\ 1468 %{!fsyntax-only:%{!S:-o %g.s} \ 1469 %{!fdump-ada-spec*:%{!o*:--output-pch%i.gch}\ 1470 %W{o*:--output-pch%*}}%V}}}}}}}, 0, 0, 0}, 1471 {.i, cpp-output, 0, 0, 0}, 1472 {cpp-output, 1473 %{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}, 0, 0, 0}, 1474 {.s, assembler, 0, 0, 0}, 1475 {assembler, 1476 %{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}, 0, 0, 0}, 1477 {.sx, assembler-with-cpp, 0, 0, 0}, 1478 {.S, assembler-with-cpp, 0, 0, 0}, 1479 {assembler-with-cpp, 1480 #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT 1481 %(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ 1482 %{E|M|MM:%(cpp_debug_options)}\ 1483 %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ 1484 as %(asm_debug) %(asm_options) %|.s %A }}}} 1485 #else 1486 %(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ 1487 %{E|M|MM:%(cpp_debug_options)}\ 1488 %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ 1489 as %(asm_debug) %(asm_options) %m.s %A }}}} 1490 #endif 1491 , 0, 0, 0}, 1492 1493 #include specs.h 1494 /* Mark end of table. */ 1495 {0, 0, 0, 0, 0} 1496 };因为gcc命令使用后缀识别源代码从而调用不同的工具所以尝试向gcc命令传递一个没有后缀的文本文件是会报错的即使文本文件的内容确实是源代码如下所示。$ gcc test test: file not recognized: File format not recognized collect2: error: ld returned 1 exit status下面我们以C语言举例了解gcc命令是如何处理C源代码文件的。// test.c #define TT 1 int main() { int aTT; }向gcc命令传递-v选项可以让其打印其在执行期间调用的所有工具如下所示。$ gcc -v test.c -o test Using built-in specs. COLLECT_GCCgcc COLLECT_LTO_WRAPPER/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix/usr --mandir/usr/share/man --infodir/usr/share/info --with-bugurlhttp://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threadsposix --enable-checkingrelease --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-stylegnu --enable-languagesc,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-tunegeneric --with-arch_32x86-64 --buildx86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) COLLECT_GCC_OPTIONS-v -o test -mtunegeneric -marchx86-64 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1 -quiet -v test.c -quiet -dumpbase test.c -mtunegeneric -marchx86-64 -auxbase test -version -o /tmp/ccifUeJP.s GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux) 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 GGC heuristics: --param ggc-min-expand100 --param ggc-min-heapsize131072 ignoring nonexistent directory /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include-fixed ignoring nonexistent directory /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/include #include ... search starts here: #include ... search starts here: /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include /usr/local/include /usr/include End of search list. GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux) 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 GGC heuristics: --param ggc-min-expand100 --param ggc-min-heapsize131072 Compiler executable checksum: d8f4c208bcaf7e279b70f7290eda3265 COLLECT_GCC_OPTIONS-v -o test -mtunegeneric -marchx86-64 as -v --64 -o /tmp/cceJQa5q.o /tmp/ccifUeJP.s GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-43.base.el7 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/ 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/ COLLECT_GCC_OPTIONS-v -o test -mtunegeneric -marchx86-64 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-stylegnu -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 -mtunegeneric -marchx86-64 -auxbase test -version -o /tmp/ccifUeJP.s细心的你可能会发现gcc命令并没有调用cppc preprocessorC预处理器这是因为这部分功能已经被整合进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-stylegnu -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语言举例说明。! add_numbers.f90 program AddNumbers implicit none integer :: number1, number2, sum ! 用户输入两个整数 print *, Enter two integers: read *, number1, number2 ! 计算两个数的和 sum number1 number2 ! 打印结果 print *, The sum of , number1, and , number2, is , sum end program AddNumbers下面直接使用gcc命令编译它输出结果如下所示。$ gcc -v add_numbers.f90 -o add_numbers Using built-in specs. COLLECT_GCCgcc COLLECT_LTO_WRAPPER/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix/usr --mandir/usr/share/man --infodir/usr/share/info --with-bugurlhttp://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threadsposix --enable-checkingrelease --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-stylegnu --enable-languagesc,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-tunegeneric --with-arch_32x86-64 --buildx86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) COLLECT_GCC_OPTIONS-v -o add_numbers -mtunegeneric -marchx86-64 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/f951 add_numbers.f90 -quiet -dumpbase add_numbers.f90 -mtunegeneric -marchx86-64 -auxbase add_numbers -version -fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/4.8.5/finclude -o /tmp/ccQACj24.s GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux) 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 GGC heuristics: --param ggc-min-expand100 --param ggc-min-heapsize131072 GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux) 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 GGC heuristics: --param ggc-min-expand100 --param ggc-min-heapsize131072 COLLECT_GCC_OPTIONS-v -o add_numbers -mtunegeneric -marchx86-64 as -v --64 -o /tmp/cctgPTMM.o /tmp/ccQACj24.s GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-43.base.el7 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/ 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/ COLLECT_GCC_OPTIONS-v -o add_numbers -mtunegeneric -marchx86-64 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-stylegnu -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 /tmp/cctgPTMM.o: In function MAIN__: add_numbers.f90:(.text0x3f): undefined reference to _gfortran_st_write add_numbers.f90:(.text0x58): undefined reference to _gfortran_transfer_character_write add_numbers.f90:(.text0x67): undefined reference to _gfortran_st_write_done add_numbers.f90:(.text0x9f): undefined reference to _gfortran_st_read add_numbers.f90:(.text0xba): undefined reference to _gfortran_transfer_integer add_numbers.f90:(.text0xd5): undefined reference to _gfortran_transfer_integer add_numbers.f90:(.text0xe4): undefined reference to _gfortran_st_read_done add_numbers.f90:(.text0x127): undefined reference to _gfortran_st_write add_numbers.f90:(.text0x140): undefined reference to _gfortran_transfer_character_write add_numbers.f90:(.text0x15b): undefined reference to _gfortran_transfer_integer_write add_numbers.f90:(.text0x174): undefined reference to _gfortran_transfer_character_write add_numbers.f90:(.text0x18f): undefined reference to _gfortran_transfer_integer_write add_numbers.f90:(.text0x1a8): undefined reference to _gfortran_transfer_character_write add_numbers.f90:(.text0x1c3): undefined reference to _gfortran_transfer_integer_write add_numbers.f90:(.text0x1d2): undefined reference to _gfortran_st_write_done /tmp/cctgPTMM.o: In function main: add_numbers.f90:(.text0x1f4): undefined reference to _gfortran_set_args add_numbers.f90:(.text0x203): undefined reference to _gfortran_set_options collect2: error: ld returned 1 exit status从上面的输出中可以看出在对fortran文件进行预处理、汇编、编译、链接的过程中gcc命令调用了f951编译器as汇编器和collect2链接器但是在最后的链接阶段却报错了错误原因是ld找不到Fortran运行时库中的一些必要函数如_gfortran_st_write等。这可以通过向gcc命令传递一些选项来解决如下所示。$ gcc -v add_numbers.f90 -lgfortran -o add_numbers Using built-in specs. COLLECT_GCCgcc COLLECT_LTO_WRAPPER/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix/usr --mandir/usr/share/man --infodir/usr/share/info --with-bugurlhttp://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threadsposix --enable-checkingrelease --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-stylegnu --enable-languagesc,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-tunegeneric --with-arch_32x86-64 --buildx86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) COLLECT_GCC_OPTIONS-v -o add_numbers -mtunegeneric -marchx86-64 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/f951 add_numbers.f90 -quiet -dumpbase add_numbers.f90 -mtunegeneric -marchx86-64 -auxbase add_numbers -version -fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/4.8.5/finclude -o /tmp/cc4GFhEz.s GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux) 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 GGC heuristics: --param ggc-min-expand100 --param ggc-min-heapsize131072 GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux) 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 GGC heuristics: --param ggc-min-expand100 --param ggc-min-heapsize131072 COLLECT_GCC_OPTIONS-v -o add_numbers -mtunegeneric -marchx86-64 as -v --64 -o /tmp/ccS7OrZX.o /tmp/cc4GFhEz.s GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-43.base.el7 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/ 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/ COLLECT_GCC_OPTIONS-v -o add_numbers -mtunegeneric -marchx86-64 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-stylegnu -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 $ ./add_numbers Enter two integers: 1 2 The sum of 1 and 2 is 3如果使用gfortran命令则无需添加选项如下所示。$ gfortran -v add_numbers.f90 -o add_numbers Driving: gfortran -v add_numbers.f90 -o add_numbers -l gfortran -l m -shared-libgcc Using built-in specs. COLLECT_GCCgfortran COLLECT_LTO_WRAPPER/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix/usr --mandir/usr/share/man --infodir/usr/share/info --with-bugurlhttp://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threadsposix --enable-checkingrelease --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-stylegnu --enable-languagesc,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-tunegeneric --with-arch_32x86-64 --buildx86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) COLLECT_GCC_OPTIONS-v -o add_numbers -shared-libgcc -mtunegeneric -marchx86-64 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/f951 add_numbers.f90 -quiet -dumpbase add_numbers.f90 -mtunegeneric -marchx86-64 -auxbase add_numbers -version -fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/4.8.5/finclude -o /tmp/ccOxqcS0.s GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux) 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 GGC heuristics: --param ggc-min-expand100 --param ggc-min-heapsize131072 GNU Fortran (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-39) (x86_64-redhat-linux) 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 GGC heuristics: --param ggc-min-expand100 --param ggc-min-heapsize131072 COLLECT_GCC_OPTIONS-v -o add_numbers -shared-libgcc -mtunegeneric -marchx86-64 as -v --64 -o /tmp/cc4yjj1R.o /tmp/ccOxqcS0.s GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-43.base.el7 Reading specs from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgfortran.spec rename spec lib to liborig COLLECT_GCC_OPTIONS-v -o add_numbers -shared-libgcc -mtunegeneric -marchx86-64 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/ 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/ COLLECT_GCC_OPTIONS-v -o add_numbers -shared-libgcc -mtunegeneric -marchx86-64 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-stylegnu -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

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询