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的手册中找到)。

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 a=TT;
}

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

$ gcc -v test.c -o test
Using built-in specs.
COLLECT_GCC=gcc
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-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
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-o' 'test' '-mtune=generic' '-march=x86-64'
 /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
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-expand=100 --param ggc-min-heapsize=131072
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-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d8f4c208bcaf7e279b70f7290eda3265
COLLECT_GCC_OPTIONS='-v' '-o' 'test' '-mtune=generic' '-march=x86-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' '-mtune=generic' '-march=x86-64'
 /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语言举例说明。

! 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_GCC=gcc
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-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
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-64'
 /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
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-expand=100 --param ggc-min-heapsize=131072
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-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-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' '-mtune=generic' '-march=x86-64'
 /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
/tmp/cctgPTMM.o: In function `MAIN__':
add_numbers.f90:(.text+0x3f): undefined reference to `_gfortran_st_write'
add_numbers.f90:(.text+0x58): undefined reference to `_gfortran_transfer_character_write'
add_numbers.f90:(.text+0x67): undefined reference to `_gfortran_st_write_done'
add_numbers.f90:(.text+0x9f): undefined reference to `_gfortran_st_read'
add_numbers.f90:(.text+0xba): undefined reference to `_gfortran_transfer_integer'
add_numbers.f90:(.text+0xd5): undefined reference to `_gfortran_transfer_integer'
add_numbers.f90:(.text+0xe4): undefined reference to `_gfortran_st_read_done'
add_numbers.f90:(.text+0x127): undefined reference to `_gfortran_st_write'
add_numbers.f90:(.text+0x140): undefined reference to `_gfortran_transfer_character_write'
add_numbers.f90:(.text+0x15b): undefined reference to `_gfortran_transfer_integer_write'
add_numbers.f90:(.text+0x174): undefined reference to `_gfortran_transfer_character_write'
add_numbers.f90:(.text+0x18f): undefined reference to `_gfortran_transfer_integer_write'
add_numbers.f90:(.text+0x1a8): undefined reference to `_gfortran_transfer_character_write'
add_numbers.f90:(.text+0x1c3): undefined reference to `_gfortran_transfer_integer_write'
add_numbers.f90:(.text+0x1d2): undefined reference to `_gfortran_st_write_done'
/tmp/cctgPTMM.o: In function `main':
add_numbers.f90:(.text+0x1f4): undefined reference to `_gfortran_set_args'
add_numbers.f90:(.text+0x203): 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_GCC=gcc
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-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
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-64'
 /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
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-expand=100 --param ggc-min-heapsize=131072
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-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-mtune=generic' '-march=x86-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' '-mtune=generic' '-march=x86-64'
 /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
$ ./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_GCC=gfortran
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-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
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' '-mtune=generic' '-march=x86-64'
 /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
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-expand=100 --param ggc-min-heapsize=131072
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-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-o' 'add_numbers' '-shared-libgcc' '-mtune=generic' '-march=x86-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' '-mtune=generic' '-march=x86-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' '-mtune=generic' '-march=x86-64'
 /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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/684777.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

X-Caps

用于对视觉属性进行编码的胶囊 补充信息 数据集太大&#xff0c;不建议复现

机器学习笔记 - 本地windows 11 + PyCharm运行stable diffusion流程简述

一、环境说明 硬件:本地电脑windows11、32.0 GB内存、2060的6G的卡。 软件:本地有一个python环境,主要是torch 2.2.2+cu118 二、准备工作 1、下载模型 https://huggingface.co/CompVishttps://huggingface.co/CompVis 进入上面的网址,我这里下载的是这个里面的 …

el-input添加clearable属性 输入内容时会直接撑开

<el-inputclearablev-if"item.type number || item.type text":type"item.type":placeholder"item.placeholder":prefix-icon"item.icon || "v-model.trim"searchform[item.prop]"></el-input>解决方案 添加c…

LLM的基础模型6:注意力机制

大模型技术论文不断&#xff0c;每个月总会新增上千篇。本专栏精选论文重点解读&#xff0c;主题还是围绕着行业实践和工程量产。若在某个环节出现卡点&#xff0c;可以回到大模型必备腔调或者LLM背后的基础模型新阅读。而最新科技&#xff08;Mamba,xLSTM,KAN&#xff09;则提…

DVWA-XSS(Stored)

Low 观察后端代码&#xff0c;对输入进行了一些过滤和转义。trim(string,charlist) 函数用于移除字符串两侧的空白字符或其他预定义字符&#xff0c;charlist 参数可以规定从字符串中删除哪些字符。stripslashes() 函数用于删除反斜杠。mysqli_real_escape_string() 函数用于对…

问题:合规电动自行车国家标准是() #学习方法#媒体#经验分享

问题&#xff1a;合规电动自行车国家标准是&#xff08;&#xff09; A&#xff0e;必须有脚踏能实现人力骑行 B&#xff0e;最高设计车速不大于25km/h C&#xff0e;整车质量不大于55kg D&#xff0e;电机输出功率不大于240w 参考答案如图所示

Linux——PXE整体流程

1.自己安装一个CentOS 8的服务器 1&#xff09;手动安装 虚拟硬件配置&#xff1a;2核CPU&#xff0c;4G内存&#xff0c;100G硬盘 2个网卡&#xff08;一个通外网&#xff0c;一个内部使用&#xff09; 软件安装&#xff1a;Server GUI 磁盘分区&#xff1a;使用逻辑卷&#…

Prometheus+Altermanager实现钉钉告警

PrometheusAltermanager实现钉钉告警 Prometheus和Altermanager的安装这里就不赘述了&#xff0c;我之前的文章有写到 不记得的小伙伴可以去看看Prometheus和Altermanager的安装使用 直接开始上操作 下载钉钉并打开&#xff0c;先创建一个接收告警信息的钉钉群 添加一个自定…

信息系统项目管理师0144:裁剪考虑因素(9项目范围管理—9.2项目范围管理过程—9.2.2裁剪考虑因素)

点击查看专栏目录 文章目录 9.2.2 裁剪考虑因素 9.2.2 裁剪考虑因素 因为每个项目都是独特的&#xff0c;所以项目经理可能根据需要裁剪项目范围管理过程。裁剪时应考虑的因素包括&#xff1a; 知识和需求管理&#xff1a;项目经理应建立哪些指南&#xff1f;为了在未来项目中…

【外汇天眼】胜率提升秘籍:洞悉外汇市场五大参与者的角色与功能

外汇市场是全球最活跃、流动性最高的金融交易市场&#xff0c;每日交易量在6万亿到11万亿美元之间。它的日交易量是全球股票市场的27倍&#xff0c;全球期货市场的12倍&#xff0c;全球债券市场的7倍&#xff0c;超过了全球所有金融产品日交易量的总和。随着全球金融一体化的进…

zeppelin 未授权任意命令执行漏洞复现

一、命令执行复现 访问http://ip:8080&#xff0c;打开zeppelin页面&#xff0c;&#xff08;zeppelin默认监听端口在8080&#xff09; 点击Notebook->create new note创建新笔记 在创建笔记的时候选择Default Interpreter为sh&#xff0c;即可执行sh命令 如下图&#x…

以hive metastore报错举例,远程调试hadoop服务

项目场景&#xff1a; CDH集群CM切换hive元数据库报错&#xff1a; com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at…

23中设计模式之一— — — —命令模式的详细介绍

命令模式 Command Pattern讲解 概念描述模式结构主要角色模式的UIM类图模式优点模式缺点应用场景实例演示类图代码演示运行结果 概念 命令模式&#xff08;别名&#xff1a;动作&#xff0c;事务&#xff09; 命令模式是一种行为设计模式&#xff0c;将一个请求封装为一个对象…

大厂真实面试题(二)

小红书大数据面试SQL-用户商品购买收藏行为特征加工 1.题目 已知有 购买记录表t_order,包含自增id:id,用户ID:user_id,商品ID:goods_id,订单时间:order_time,商品类别:goods_type; 用户收藏记录表t_collect_log,包含自增id,用户ID:user_id,商品ID:goods_id,收藏时间 c…

【WP】猿人学15_备周则意怠_常见则不疑

https://match.yuanrenxue.cn/match/15 抓包分析 抓包分析有一个m参数&#xff0c;三个数字组成 追栈/扣代码 根据启动器顺序追栈&#xff0c;一般优先跳过 jQuery 直接能找到加密函数 每次获取的数字都不一样 window.m function() { t1 parseInt(Date.parse(new Date(…

优思学院|谈汽车零部件企业生产精益及现场管理

精益生产&#xff08;Lean Production&#xff09;和现场管理作为现代制造企业的核心管理理念&#xff0c;正在越来越多的企业中得到应用。尤其是在中国&#xff0c;许多汽车零部件企业通过精益管理和六西格玛方法&#xff0c;显著提高了生产效率&#xff0c;降低了生产成本&am…

红酒:如何选择适合的红酒储存容器

选择适合的红酒储存容器对于保持雷盛红酒的品质和风味至关重要。不同的容器具有不同的优缺点&#xff0c;因此应根据个人需求和条件进行选择。以下是一些常见的红酒储存容器的特点和适用场景&#xff1a; 玻璃瓶&#xff1a;玻璃瓶是常见的红酒储存容器。它具有良好的密封性能、…

点云获取pcl点云以某个点云的已经分块得区域的交集

首先将点云分块得到区域后&#xff0c;获取每个块的box的最大最小点云&#xff0c;然后提取box内的点云。 pcl::IndicesPtr indexes(new pcl::Indices());pcl::getPointsInBox(*cloud_1, min_pt, max_pt, *indexes);// --------------------------取框内和框外点--------------…

iPhone 存储不足?快速释放空间的实用技巧

想象一下&#xff0c;您的iPhone上充满了GIF、照片、群聊记录、音乐和游戏。它可能已经成为您存储数据的核心设备&#xff0c;因此很容易就会填满存储空间。尽管iPhone 15和iPhone 14的起始存储容量提升到了128GB&#xff0c;但这对于一些用户来说可能仍然不够用。因此&#xf…

解决国内无法访问huggingface.co

在国内无法访问 https://huggingface.co 时&#xff0c;可以使用国内的镜像站点&#xff1a; HF-Mirror - Huggingface 镜像站加速访问Hugging Face的门户。作为一个公益项目&#xff0c;我们致力于提供稳定、快速的镜像服务&#xff0c;帮助国内用户无障碍访问Hugging Face的…