Home >Backend Development >C++ >Why Does My C Code Get 'undefined reference to 'std::cout'' and How Do I Fix It?
Undefined Reference to 'std::cout'
When compiling C programs that utilize the standard library, such as
One potential solution is to use the appropriate C compiler, such as g , which can automatically link to the standard library. Alternatively, when using gcc, explicit linking with -lstdc is necessary, as follows:
gcc main.cpp -lstdc++ -o main.o
To quell warnings during compilation, consider using the -Wall and -Wextra flags:
g++ -Wall -Wextra -Werror -c main.cpp -o main.o
The above is the detailed content of Why Does My C Code Get 'undefined reference to 'std::cout'' and How Do I Fix It?. For more information, please follow other related articles on the PHP Chinese website!