74

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?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Adam Sh
  • 8,137
  • 22
  • 60
  • 75

13 Answers13

101
  1. Click Project → Properties.
  2. Expand C/C++ General.
  3. Click Preprocessor Include Paths, Macros, etc.
  4. Click the Providers tab.
  5. Check CDT GCC Built-in Compiler Settings.
  6. Check Use global provider shared between projects. Preprocessor Properties
  7. Click Apply and Close.
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Alan CN
  • 1,467
  • 1
  • 13
  • 13
  • I got a Unsolved inclusion from #include . But it worked to me. Thanks! – Natanael Feb 23 '14 at 12:14
  • 1
    This worked for me. I still got flaky behaviour similar to Natanael until I deleted the project, re-imported, cleand and re-built. – Jacko Jun 21 '14 at 03:24
  • I then also needed to set "Command to get compiler specs" in Eclipse Photon under Linux: https://stackoverflow.com/a/51099533/895245 – Ciro Santilli OurBigBook.com Jun 29 '18 at 10:22
  • For me it was `CDT GCC Built-In Compiler Settings Cross ARM` but the bloody eclipse always used gcc instead of my arm-none-eabi-gcc. After two hours realized I had to uncheck and recheck the setting to force eclipse to rerun the scanner. – buergi Sep 18 '18 at 21:31
18

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

Tod
  • 8,192
  • 5
  • 52
  • 93
13

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

lyz
  • 548
  • 6
  • 16
6

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

ChrisHD
  • 61
  • 1
  • 2
4

Install gcc.

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

If you're on Windows, use MinGW.

Dhaivat Pandya
  • 6,499
  • 4
  • 29
  • 43
  • 8
    Installing gcc is not always sufficient to resolve the inclusion. – ehudt May 01 '13 at 14:44
  • Solves the problem 99% of the time. Why else would iostream not load, unless there's something terribly wrong with your system? I think that we could say this sort of response for every answer, e.g. if its a syntax error and someone fixes it, the response could be, "it could be the compiler that has a bug". But, the chances of that happening are pretty low. – Dhaivat Pandya May 02 '13 at 00:40
  • 2
    @DhaivatPandya: I think he means installing gcc is only one of several required steps. (Unless eclipse can magically detect that gcc was suddenly installed? It might, I don't know) – Mooing Duck Jan 31 '14 at 00:58
  • 2
    Note that I used eclipse for a month working on a project, and suddenly all my #include statements got this warning (gcc obviously installed), so installing gcc is not a real solution. – GreySage Nov 17 '15 at 19:10
3

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>.

Pedro Gordo
  • 1,825
  • 3
  • 21
  • 45
2

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

nukerebel
  • 119
  • 1
  • 8
1

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]".

superm0
  • 963
  • 11
  • 19
1

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++
Alex Byrth
  • 1,328
  • 18
  • 23
1

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.

yadhu
  • 1,253
  • 14
  • 25
1

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.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
0

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.

Xavier Lamorlette
  • 1,152
  • 1
  • 12
  • 20
0

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.

Shawn
  • 621
  • 5
  • 10