gcc编译c++的选项以及gcc与g++编译c++代码的区别

本文介绍了GCC和G++编译器的使用方法,重点讲解了如何通过-x选项指定源文件的语言类型,以及如何利用G++自动链接C++库进行编译。同时,对比了GCC与G++在处理不同文件扩展名时的行为差异。

   

$ gcc --help

  -x <language>            Specify the language of the following input files
                           Permissible languages include: c c++ assembler none
                           'none' means revert to the default behavior of
                           guessing the language based on the file's extension

$g++ --help

  -x <language>            Specify the language of the following input files
                           Permissible languages include: c c++ assembler none
                           'none' means revert to the default behavior of
                           guessing the language based on the file's extension


Compiling C++ Programs

       C++ source files conventionally use one of the suffixes .C, .cc, .cpp, .CPP, .c++, .cp, or .cxx; C++ header files often
       use .hh, .hpp, .H, or (for shared template code) .tcc; and preprocessed C++ files use the suffix .ii.  GCC recognizes
       files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C
       programs (usually with the name gcc).


       However, the use of gcc does not add the C++ library.  g++ is a program that calls GCC and automatically specifies
       linking against the C++ library.  It treats .c, .h and .i files as C++ source files instead of C source files unless -x
       is used.  This program is also useful when precompiling a C header file with a .h extension for use in C++ compilations.
       On many systems, g++ is also installed with the name c++.


       When you compile C++ programs, you may specify many of the same command-line options that you use for compiling programs
       in any language; or command-line options meaningful for C and related languages; or options that are meaningful only for

       C++ programs.


gcc 如果指定 -xc++  就会将输入文件认为是c++文件   g++也有对应选项

gcc不会自动链接c++库,g++在调用gcc时自动链接的是c++库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值