Difference between CC, gcc and g ++?

What is the difference between the three CC, gcc, g ++ compilers when compiling C and C ++ in terms of assembly, code generation, available libraries, language functions, etc.?

+63
c ++ c gcc compilation
04 Oct '09 at 14:55
source share
3 answers

The answer to this depends on the platform; what happens on Linux is different than what happens on Solaris, for example.

The easy part (because it is not platform specific) is the separation of "gcc" and "g ++":

  • gcc is the GNU C compiler from GCC (the GNU compiler compilation).
  • g ++ is the GNU C ++ compiler from GCC.

The hard part, because it is platform specific, has the value "CC" (and "cc").

  • In Solaris, CC is usually the name of the Sun C ++ compiler.
  • In Solaris, cc is usually the name of the Sun C compiler.
  • On Linux, if it exists, CC is probably a reference to g ++.
  • On Linux, cc is a reference to gcc.

However, even on Solaris, it could be that cc is an old BSD-based C compiler from /usr/ucb . In practice, this is usually not installed, and there is only a stub that fails, damaging those who are trying to compile and install self-tuning software.

In HP-UX, by default, β€œcc” is still the K & R-only C compiler, which allows you to restart the kernel when necessary, and is unsuitable for use in modern programs, since it does not support the C standard. You have to use alternative compiler names ('acc' IIRC). Similarly, on AIX, the C system compiler has names such as "xlc" or "xlc32".

Classically, the system compiler was called "cc" by default, and self-tuning software returns to that name when it does not know what else to use.

POSIX tried to legislatively make its way by demanding that c89 (initially) and then c99 exist; they are compilers compatible with ISO / IEC 9899: 1989 and 9899: 1999 C standards. It is doubtful that POSIX succeeded.




The question asks about differences in functionality and libraries. As before, the answer is partly platform dependent, and partly part.

The big difference between C compilers and C ++ compilers. C ++ compilers will accept C ++ programs and will not compile arbitrary C programs. (Although you can write C in a subset that C ++ also understands, many C programs are not valid C ++ programs). Similarly, C compilers will accept C programs and reject most C ++ programs (since most C ++ programs use constructs not available in C).

Available libraries may vary by language. C ++ programs can usually use C libraries on a given platform; C programs usually cannot use C ++ libraries. Thus, C ++ has a larger set of libraries available.

Note that if you are on Solaris, the object code generated by CC is incompatible with the object code created by g ++ - these are two separate compilers with separate conventions for operations such as exception handling and name manipulation (and name distortion intentionally differs in that that incompatible object files are not related to each other!). This means that if you want to use a library compiled with CC, you must compile your entire program using CC. It also means that if you want to use one library compiled with CC and another compiled with g ++, you're out of luck. You must recompile one of the libraries at a minimum.

Regarding assembler build quality, GCC (the GNU compiler compilation) does a very good job. But sometimes native compilers work a little better. I believe Intel compilers have more extensive optimizations that have not yet been replicated to GCC. But any such warnings are dangerous until we know which platform you are working on.

In terms of language features, compilers are generally generally quite close to current standards (C ++ 98, C ++ 2003, C99), but usually there are slight differences between the standard language and the language supported by the compiler. The old standard C89 support is essentially the same (and complete) for all C compilers. There are differences in the darker corners of the language. You need to understand "undefined behavior", "system-defined behavior" and "undefined behavior"; if you invoke undefined behavior, you will get different results at different times. There are also many options (especially with GCC) for customizing compiler behavior. GCC has many extensions that make life easier if you know that you only target this family of compilers.

+91
Oct 04 '09 at 15:24
source share

CC is an environment variable related to the compiler of system C. What it points to (available libraries, etc.) depends on the platform. Often it points to /usr/bin/cc , the actual c complier (driver). On Linux platforms, CC almost always points to /usr/bin/gcc .

gcc is the driver binary for the GNU compiler collection. It can compile C, C ++, and possibly other languages; It defines the language with the file extension.

g++ is a driver binary, such as gcc , but with a few special parameters set to compile C ++. Remarkably (in my experience), g++ will bind libstdC ++ by default, and gcc will not.

+20
04 Oct '09 at 15:04
source share

I want to add only one information that cc is on Linux. It is associated with gcc. Check it out. enter image description here

Similarly, with c ++.

 uddhavpgautam@UbuntuServer1604:~/Desktop/c++$ whereis c++ c++: /usr/bin/c++ /usr/include/c++ /usr/share/man/man1/c++.1.gz uddhavpgautam@UbuntuServer1604:~/Desktop/c++$ ls -l /usr/bin/c++ lrwxrwxrwx 1 root root 21 Jul 31 14:00 /usr/bin/c++ -> /etc/alternatives/c++ uddhavpgautam@UbuntuServer1604:~/Desktop/c++$ ls -l /etc/alternatives/c++ lrwxrwxrwx 1 root root 12 Jul 31 14:00 /etc/alternatives/c++ -> /usr/bin/g++ 
0
Aug 13 '18 at 15:07
source share



All Articles