What is the difference between g++ and gcc?

后端 未结 10 2363
无人共我
无人共我 2020-11-22 00:34

What is the difference between g++ and gcc? Which one of them should be used for general c++ development?

10条回答
  •  孤街浪徒
    2020-11-22 00:53

    What is the difference between g++ and gcc?

    gcc has evolved from a single language "GNU C Compiler" to be a multi-language "GNU Compiler Collection". The term "GNU C Compiler" is still used sometimes in the context of C programming.

    The g++ is the C++ compiler for the GNU Compiler Collection. Like gnat is the Ada compiler for gcc. see Using the GNU Compiler Collection (GCC)

    For example, the Ubuntu 16.04 and 18.04 man g++ command returns the GCC(1) manual page.

    The Ubuntu 16.04 and 18.04 man gcc states that ...

    g++ accepts mostly the same options as gcc

    and that the default ...

    ... 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.

    Search the gcc man pages for more details on the option variances between gcc and g++.

    Which one should be used for general c++ development?

    Technically, either gcc or g++ can be used for general C++ development with applicable option settings. However, the g++ default behavior is naturally aligned to a C++ development.

    The Ubuntu 18.04 'gcc' man page added, and Ubuntu 20.04 continues to have, the following paragraph:

    The usual way to run GCC is to run the executable called gcc, or machine-gcc when cross-compiling, or machine-gcc-version to run a specific version of GCC. When you compile C++ programs, you should invoke GCC as g++ instead.

提交回复
热议问题