How to solve “Unresolved inclusion: <iostream>” in a C++ file in Eclipse CDT?

£可爱£侵袭症+ 提交于 2019-11-27 00:54:34
Alan CN

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

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.

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

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

Install gcc.

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

If you're on Windows, use MinGW.

In my case it was not the CDT GCC Built-in Compiler Settings. On by including CDT GCC Built-in Compiler Settings Cygwin did the parser recognized my #include <iostream>.

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

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

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

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.

Also set "Command to get compiler specs" ${COMMAND} on Linux

First do:

  • Project
  • Properties
  • C/C++ General
  • Preprocessor Include Paths, Macros, etc.
  • Providers

and then under: "Command to get compiler specs" replace:

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

with:

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

Otherwise, it fails with:

Unable to find compiler command in toolchain=cdt.managedbuild.toolchain.gnu.base

Tested on Eclipse Photon Release Candidate 3 (4.8.0RC3), Ubuntu 16.04, and this minimal Makefile project with existing sources.

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