107

I set up CDT for eclipse and wrote a simple hello world C program:

#include <stdio.h>

int main(void){
    puts("Hello, world.");
    return 0;
}

The program builds and runs correctly, but eclipse keeps showing this yellow question mark by the side of inclusion statement that says "Unresolved inclusion: <stdio.h>" when I put mouse over it.

It doesn't affect running of the program but I find it rather annoying.

Does anyone have any idea how to remove it?

Neuron
  • 5,141
  • 5
  • 38
  • 59
Derrick Zhang
  • 21,201
  • 18
  • 53
  • 73
  • 2
    You would think that the Hello World example would do this for you, or at least provide some help. If eclipse doesn't include a compiler, why doesn't it? – Doug Molineux Aug 03 '12 at 21:07
  • http://stackoverflow.com/questions/7905025/string-could-not-resolved-error-in-eclipse-for-c – Vanuan Oct 22 '12 at 10:07

14 Answers14

58

I found these answers (including the accepted one) somewhat cryptic.

For me, I had to add the path where stdio.h is located (as @ardnew said). In Eclipse, you open the Properties of your project, expand "C/C++ General" and select "Paths and Symbols".

Make sure you have added the include dir for each language you are using. (In my case, I needed to just add it to GNU C++.)

Screenshot of Eclipse "Project Properties" dialog with "Paths and Symbols" selected. An "add directory path" dialog is overlaid.

aaaidan
  • 7,093
  • 8
  • 66
  • 102
  • 1
    This is eerily close to what I needed! Just had to change the user name in the path. – Lucas Oct 08 '13 at 08:26
  • 2
    On OS X you may need to manually install the command line developer tools (which first requires installing Xcode) using the command `/usr/bin/xcode-select --install` and then you'll be able to point Eclipse at `/usr/include/` – RobV Apr 15 '14 at 22:24
  • 1
    On Yosemite. Using Eclipse Juno. This kind of worked for me except the path I had give was bit different (/Users/SrinivasanNatarajan/android-ndk/platforms/android-19/arch-arm/usr/include). Even though all the unresolved errors disappeared I still have a doubt that 'did I set the correct path'. "Eclipse really sucks". Had to spend hours in order to setup the IDE for development. – Srinivasan N Apr 01 '15 at 10:22
  • 1
    Thanks. Only your variant helphed me. – Nikmoon Dec 20 '16 at 09:18
  • In my case (with MinGW), used "File system..." to add directory "C:\MinGW\include" – Gary99 Jan 04 '18 at 15:54
  • please note that in some cases the system includes are spread in multiple folders! it was my case, I wasted a lot of time because apparently this solution of adding a folder wasn't working. But actually you need to pay attention and find where each .h is stored, in your system. – HAL9000 Jun 08 '18 at 11:11
  • Unfortunately under Eclipse 4.11 "Paths and Symbols" does not exist anymore, which makes this answer slightly outdated. – Brainsucker92 May 08 '19 at 23:15
  • I have made this a "community wiki" answer, so please update the screenshot and instructions if so inclined. @Brainsucker92 – aaaidan Nov 12 '20 at 18:45
55

The compiler Eclipse is using is able to resolve the symbols just fine, so the code will compile fine.

But the code-completion/indexer or preprocessor Eclipse is using doesn't know where stdio.h exists.

You need to specify the filesystem path where stdio.h is located.

The Eclipse documentation describes this in several sections for the compiler:

And if the code-completion/indexer or preprocessor specifically also cannot locate stdio.h:

The exact location of stdio.h will depend on the system you are intending to write the code for. If you are writing code for the same system you are running Eclipse on, then the standard location is /usr/include/stdio.h for Linux, macOS, Cygwin, etc.

If you are cross-compiling for a separate/remote target system (e.g. Android, Raspberry Pi, STM32), then it will be located somewhere in the SDK you installed for that system. You will need to refer to that particular SDK documentation.

ardnew
  • 2,028
  • 20
  • 29
  • 2
    Thanks for the reply. But where is the path for Ubuntu 11.10 ? – Derrick Zhang Feb 18 '12 at 02:23
  • One thing that confused me was that I had to add the path to the "includes" tab, rather than the "library paths" tab. I always thought that "anglebracket" includes were "library" includes. – aaaidan Jul 07 '12 at 05:24
  • 1
    You specify where to find header files (i.e. .h files) on the includes tab. You tell the linker where it can find compiled library files on the library path tab. The convention of quotes vs angle brackets is probably compiler dependent but I always think of <> as meaning look first in the standard system library place and "" as meaning looking in my project first. – Tod Jul 26 '12 at 05:17
  • 2
    Modern compilers make no distinction between quotes and angle brackets. Conventionally standard system headers are still placed in angle brackets. – Seppo Enarvi Aug 13 '12 at 08:54
19

Go to Project > Properties > C/C++ General > Preprocessor Includes > Providers and select both:

  • "CDT GCC Built-in Compiler Settings"
  • "CDT CROSS GCC Built-in Compiler Settings"

For each one of those also select the sub-entry: "Use global provider shared between projects".

Tested on Eclipse 4.8.0 in Ubuntu 16.04 with a C and a C++ hello world.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Mike B
  • 1,522
  • 1
  • 14
  • 24
  • 4
    ...and check the "Use global provider shared between projects" box – Urhixidur Dec 06 '16 at 17:39
  • I had to also check the "Use global provider shared between projects" as @Urhixidur mentioned. I tried a large number of solutions to this built in eclipse error and this is the one that actually worked for me. Those lines were annoying. Thanks! – CodeGuyRoss Sep 26 '17 at 15:42
17

just adding to the knowledge base, i just did this on win7 with cygwin.

this is what seems to work for me.

include paths for c:

D:\dev\cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include
D:\dev\cygwin\usr\include

include paths for c++:

D:\dev\cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include
D:\dev\cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include\c++
D:\dev\cygwin\usr\include

this gets me a clean compile of hello world.

Ray Tayek
  • 9,841
  • 8
  • 50
  • 90
  • I am from the future. I have come to say thank you. This is actually the first thing that worked for me. Ive never had such a difficult hello world. Thank you sir. – nVentimiglia Jul 13 '14 at 15:57
11
  • Select File>>New Project
  • In the Project Wizard, select C/C++>> C++ Project
  • In "Project type" section, select "Makefile Project>> Hello world C++ Project"
  • In "Toolchains" section, select "Linux GCC"

It can solve the problem. (Excuse me for bad English)

4

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
4

I'm working with multiple cross compiler configurations, where I need to use different locations for the STD header files (and other environment variables).

The solution was to set up the indexer so it uses the active configuration.
Unfortunately due to some bug in eclipse, the option isn't stored locally, so you have to use the workspace configuration if you want to save the configuration when you open eclipse again.

Window -> Preferences -> C/C++ -> Indexer -> Use active build configuration

This will make eclipse use the right compiler that is set with the project's active Cross GCC configuration.

Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185
  • Had the same issue, cross-compiling to ESP8266. Too bad this page is so crowded, had to figure it out myself. – Michael Böckling May 07 '16 at 12:35
  • Thank you for this. I also had this problem develop after I created multiple cross compiler configurations (for different versions of the ESP32 "ESP-IDF" embedded SDK). The correct headers were not being picked up by the Indexer. This setting seems to allow the Indexer to use the same environment as the active configuration, which in my case allowed it to pick up the right headers. – davidA Jan 17 '18 at 02:32
  • I have this option checked but it doesn't fix the problem. Eclipse is totally schizophrenic. Sometimes I don't get these errors but then sometimes it decides I have unrecognized headers and symbols all over the place. I have not yet been able to correlate when it occurs and resolves based upon actions I take, other than I change code, save it, and rebuild it. – lurker Mar 25 '22 at 17:08
4

As the top answers note, it's necessary to specify where the build folders are located, which can be added via a dialog reached by right-clicking the project, and selecting Properties->C/C++ General->Paths and Symbols.

The remaining question is what paths need to be added.

If you have gcc set up correctly for command-line access, and need to know what the default include paths it uses are, just ask it; depending on which language you're interested in, use:

gcc -x c -v -E /dev/null
gcc -x c++ -v -E /dev/null

...this will list the default compiler settings that are used when invoking gcc (and this command also works if "gcc" is really an alias for clang, as on OSX).

/dev/null is used as an empty file - we're telling gcc to parse an empty file

-x <language> specifies the language to compile as, necessary because we're not using a file with an extension that specifies the language

-v verbose output, which includes outputting the include paths

-E only perform preprocessing, output the preprocessed file (this prevents gcc from complaining that an empty file doesn't compile correctly)

Toward the bottom will be the list of include directories:

#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks (framework directory)
End of search list.

If you enter the directories listed here, in the order listed, into Eclipse's paths and symbols dialog, Eclipse CDT should be able to find the standard headers, and perhaps some additional headers specific to your OS.

(With thanks to devnull's answer to a related question.)

Community
  • 1
  • 1
Theodore Murdock
  • 1,538
  • 1
  • 13
  • 28
1

In ADT I did the following:

  1. right click on the project and select Properties
  2. expand C/C++ General and select Preprocessor Include Paths, Macros etc.
  3. select CDT User Setting Entries
  4. select Add... from the right hand menu
  5. In the Add Include Directory change Project Path to File System Path
  6. Browse to the directory that contains your include files
  7. stir and repeat as needed
user330844
  • 872
  • 1
  • 12
  • 12
1

Normally, Eclipse should be able to automatically resolve the standard include files. It does this by calling gcc and asking its configuration. Most likely Eclipse is not finding your gcc (or at least not the version you use for compiling).

Instead of specifying all the standard include paths in project settings, you probably want to make sure Eclipse finds gcc. Add the directory where gcc is found to PATH environment variable before starting Eclipse.

If you want different projects to use different compilers, then you might want to tweak the discovery options. These are hidden by default, so first enable them from Window > Preferences > C/C++ > Property Pages Settings > Display "Discovery Options" page. Then you can find them under C/C++ Build > Discovery Options in project properties.

Seppo Enarvi
  • 3,219
  • 3
  • 32
  • 25
1

I m using eclipse based CodeWarrior IDE for embedded projects and i have just solved this problem by deleting and adding again the source adresses to Project Properities->C/C++ General->Path and Sybols-> Include Directories. This means that there lots of reason to take "Unresolved inclusion:" message and there r lots of solution too.

Enes Akyay
  • 3
  • 1
  • 2
0

An error I had configuring Paths and Symbols is that initially I configued the include paths for a different language. I'm working with CDT and Cygwin gnu C++. So you must configure symbols and paths under GNU C++ language.enter image description here

rodolk
  • 5,606
  • 3
  • 28
  • 34
0

Also set ${COMMAND} to gcc 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:

gcc -std=c99 -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: How to solve "Unresolved inclusion: <iostream>" in a C++ file in Eclipse CDT?

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
  • I wonder how `${COMMAND}` is normally populated — why is it undefined for you? This seems like a more correct answer anyway, as it enables `gcc` to discover its own paths automatically. – ardnew Oct 11 '21 at 16:52
  • @ardnew I wish I knew, but not brave enough to read source. So you don't reproduce? Your `COMMAND` is set on a clean Eclipse install? Which system/Eclipse version? – Ciro Santilli OurBigBook.com Oct 11 '21 at 17:58
0

Do you check if it's compile from command line? For me helps on Linux, apt install libc-dev.

Jan B Noir
  • 11
  • 2