Comparison and difference between gcc and g++ in C and C++
- 2020-05-26 09:51:09
- OfStack
Comparison and difference between gcc and g++ in C/C++
1. The difference between
1. gcc is the c compiler in GCC
g++ is the c++ compiler in GCC
2. For files with the suffix.c, gcc is treated as c, while g++ is treated as c++
For files with a.cpp suffix, both are treated as.cpp files
3. During the build phase, g++ will automatically link to the STL library, while gcc must add one parameter -lstdc++
4. When gcc compiles c files, there are relatively few predefined macros available
2. A small error
1.gcc can only be used to compile.c files, and g++ can only be used to compile.cpp files
A: either is fine. For files with the suffix.c, gcc is treated as c, while g++ is treated as c++
For files with a.cpp suffix, both are treated as.cpp files
2. Compile only gcc, link only g++
A: no. Both gcc and g++ are used in the build phase, g++ is used in the link phase, and g++ is used in the build phase with one parameter -lstdc++.
3.gcc does not define -cplusplus macros, while g++ does
A: wrong. This macro simply indicates whether the compiler interprets the code as c or c++.
Above is the C/C++ gcc and g++ comparison and differences in details, if you have any questions please leave a message or to the site community comments for discussion, thank you for reading, hope to help you, thank you for your support of the site!