Home >Backend Development >C++ >GCC vs. G : Why Use G for C Compilation?

GCC vs. G : Why Use G for C Compilation?

DDD
DDDOriginal
2024-11-26 11:24:13748browse

GCC vs. G  : Why Use G   for C   Compilation?

Compiling C with GCC and the Difference Between GCC and G

While GCC is known for compiling C programs, it can also compile C code. The errors encountered when attempting to compile info.c using "gcc info.C" are not compiler errors but linker errors.

To resolve the linking issue, it is necessary to add the "-lstdc " flag to the compilation command:

gcc info.C -lstdc++

This tells the linker to link the program against the standard C library.

However, for simplicity, it is recommended to use g for compiling C programs.

Difference Between GCC and G

As explained by Rup in a comment on another answer:

  • Both gcc and g choose the appropriate back-end compiler based on the file extension (.c or .cc).
  • gcc links against the standard C and GCC helper libraries by default, regardless of input language.
  • g includes libstdc in its link step, regardless of input language.
  • g compiles all C source (.c) as C .

The above is the detailed content of GCC vs. G : Why Use G for C Compilation?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn