Home >Backend Development >C++ >Why Does My C Program Fail to Link with GCC, and How Can I Fix It?
Compiling a C Program with GCC
While GCC is indeed capable of compiling C programs, the error you encountered indicates a linking issue rather than a compilation error.
To resolve the problem, append the -lstdc flag to your compilation command, which will instruct the linker to include the standard C library.
gcc info.C -lstdc++
A more convenient option is to use g instead of gcc. g automatically selects the appropriate back-end compiler based on file extension (.c for C, .cpp for C ) and includes the standard C library in the linking step.
The key difference between gcc and g is that g selects the C compiler (g ) for all source files, including those with the .c extension. g also enables additional compiler features specifically designed for C .
The above is the detailed content of Why Does My C Program Fail to Link with GCC, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!