Home >Backend Development >C++ >Why Does Compiling `info.c` with GCC Require the `-lstdc ` Flag?
Compiling C Programs with GCC
While GCC is capable of compiling C code, the compiler errors encountered when attempting to compile "info.c" are due to linker errors. These errors stem from the lack of linking to the standard C library.
To resolve this issue, add the -lstdc flag to the compilation command:
gcc info.C -lstdc++
Alternatively, a simpler solution is to utilize g , which does the following:
The following excerpt from a comment by Rup succinctly explains the differences:
"GCC will select the correct back-end compiler based on file extension. However, it links binaries against just the standard C and GCC helper libraries by default. In contrast, g includes libstdc in its linking step by default, regardless of input languages."
The above is the detailed content of Why Does Compiling `info.c` with GCC Require the `-lstdc ` Flag?. For more information, please follow other related articles on the PHP Chinese website!