[c++] How to solve "Unresolved inclusion: <iostream>" in a C++ file in Eclipse CDT?

I download eclipse for c++ (cdt-master-8.0.2.zip).

When I write:

#include <iostream>

It marks:

Unresolved inclusion: <iostream>

How can I fix it?

This question is related to c++ eclipse iostream

The answer is


I'd had this issue with Eclipse 2019-12 where the includes were previously being resolved, but then weren't. This was with a Meson build C/C++ project. I'm not sure exactly what happened, but closing the project and reopening it resolved the issue for me.


Make sure that your file has .cpp extension and not .c, I just had this problem


I am running eclipse with cygwin in Windows.

Project > Properties > C/C++ General > Preprocessor Includes... > Providers and selecting "CDT GCC Built-in Compiler settings Cygwin" in providers list solved problem for me.


Go to Project > Properties > C/C++ General > Preprocessor Includes... > Providers and select "CDT GCC Built-in Compiler Settings".


In my case, it was not the CDT GCC Built-in Compiler Settings. Only after I included CDT GCC Built-in Compiler Settings Cygwin did the parser recognized my #include <iostream>.


On Windows, with Eclipse CDT Oxygen, none of the solutions described here worked for me. I described what works for me in this other question: Eclipse CDT: Unresolved inclusion of stl header.


For those using a fresh install of Ubuntu, or another Linux distro, make sure your have at least the package "build-essential" before you try to compile Eclipse CDT projects.

At Terminal, type:

sudo apt-get install build-essential

It should be enough to compile and run your apps.

Of course, you can also perform full g++ install, using:

sudo apt-get install g++

I'm using Eclipse with Cygwin and this worked for me:

Go to Project > Properties > C/C++ General > Preprocessor Includes... > Providers and select "CDT GCC Built-in Compiler Settings Cygwin [Shared]".


It sounds like you haven't used this IDE before. Read Eclipse's "Before You Begin" page and follow the instructions to the T. This will make sure that Eclipse, which is only an IDE, is actually linked to a compiler.

http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_before_you_begin.htm


Also set ${COMMAND} to g++ on Linux

Under:

  • Project
  • Properties
  • C/C++ General
  • Preprocessor Include Paths, Macros, etc.
  • Providers
  • CDT GCC Built-in Compiler Settings
  • Command to get compiler specs

Replace:

${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"

with:

g++ -std=c++11 -E -P -v -dD "${INPUTS}"

If you don't do this, the Eclipse stdout shows:

Unable to find full path for "-E"

and logs under ${HOME}/eclipse-workspace/.metadata/.log show:

!ENTRY org.eclipse.cdt.core 4 0 2020-04-23 20:17:07.288
!MESSAGE Error: Cannot run program "-E": Unknown reason

because ${COMMAND} ${FLAGS} are empty, and so Eclipse tries to execute the -E that comes next.

I wonder if we can properly define the COMMAND and FLAGS variables on the settings, but I tried to add them as build variables and it didn't work.

C version of the question: "Unresolved inclusion" error with Eclipse CDT for C standard library headers

Tested on Eclipse 2020-03 (4.15.0), Ubuntu 19.10, and this minimal Makefile project with existing sources.


I tried all previously mentioned answers, but in my case I had to manually specify the include path of the iostream file. As I use MinGW the path was:

C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++

You can add the path in Eclipse under: Project > C/C++ General > Paths and Symbols > Includes > Add. I hope that helps


I use Eclipse for cross compiling and I have to add the explicit directories for some of the standard C++ libraries. Right click your project and select Properties. You'll get the dialog shown in the image. Follow the image and use the + icon to explicitly add the paths to your C++ libraries. enter image description here


Install gcc.

If you're on linux, use the package manager.

If you're on Windows, use MinGW.


Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to iostream

'cout' was not declared in this scope How to read line by line or a whole text file at once? How to print Unicode character in C++? Why std::cout instead of simply cout? operator << must take exactly one argument How to solve "Unresolved inclusion: <iostream>" in a C++ file in Eclipse CDT? Why is reading lines from stdin much slower in C++ than Python? How to print (using cout) a number in binary form? Why would we call cin.clear() and cin.ignore() after reading input? Reading a file character by character in C