“Unresolved inclusion” error with Eclipse CDT for C standard library headers

六月ゝ 毕业季﹏ 提交于 2019-11-27 06:31:13

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

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

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

See: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/tasks/cdt_t_proj_paths.htm

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

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.

Mike B

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.

  • 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)

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

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.

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

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.

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!