Coding⏱️ 2 min read📅 2026-05-31

How to Fix: Error "undefined reference to 'std::cout'"

Undefined reference to std::cout error in C++.

Quick Answer: The error occurs because the compiler cannot find the definition of std::cout. Add #include at the top of your code to fix the issue.

To resolve the "undefined reference to `std::cout`" error, you need to link against the C++ standard library. This is typically done by adding the `-lstdc++` flag when compiling your code.

✅ Best Solutions to Fix It

Method 1: Adding the `-lstdc++` Flag

  1. Step 1: Open your terminal or command prompt and navigate to the directory where your source file is located.

Method 2: Using a Build System

  1. Step 1: If you're using a build system like CMake or Qt Creator, make sure that the standard library is included in your project settings.

🎯 Final Words

By following these steps, you should be able to resolve the "undefined reference to `std::cout`" error and get your code compiling successfully.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions