Eclipse CDT Builtin Include Directories - c++

Under
Eclipse CDT >
Project Settings >
C/C++ General >
Paths and Symbols >
Includes >
GNU C++
There is a list of include paths.
Some are in bold and are project specific.
Others are builtin:
For example:
/usr/include/C++/4.6/
/usr/include/x86_64-linux-gnu
etc
If I delete:
work/.metadata/.plugins/org.eclipse.cdt.make.core/*.sc
The paths are automatically rescanned when Eclipse launches.
I have gcc 4.6 and gcc 4.7 installed side-by-side.
When Eclipse rescans it only finds the 4.6 headers and not the 4.7 ones.
My question is this: By what mechanism does Eclipse determine the list of builtin include paths? (and hence why is it only finding the 4.6 headers and not the 4.7 headers?)

This is controlled by the settings on Project->Properties->C/C++ Build->Discovery Options. By default, Eclipse will call g++ to discover the include directories. The first instance of g++ on the path will be the one that gets invoked. You can always set the full path to the compiler you want it to use for your project.

Related

Unresolved Inclusions using C++ [duplicate]

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?
Click Project → Properties.
Expand C/C++ General.
Click Preprocessor Include Paths, Macros, etc.
Click the Providers tab.
Check CDT GCC Built-in Compiler Settings.
Check Use global provider shared between projects.
Click Apply and Close.
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. Only after I included 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.
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.
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.
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.

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?
Click Project → Properties.
Expand C/C++ General.
Click Preprocessor Include Paths, Macros, etc.
Click the Providers tab.
Check CDT GCC Built-in Compiler Settings.
Check Use global provider shared between projects.
Click Apply and Close.
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. Only after I included 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.
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.
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.
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.

Eclipse indexer can't resolve shared_ptr

After researching this on the internet, I've been unable to get the Eclipse indexer to resolve "shared_ptr" from the C++0x additions that come with GCC 4.4.4. I made sure to create my project with the proper includes for Eclipse, so it's definitely looking in the the 4.4.4 include folders.
The program compiles and runs just fine. To access shared_ptr I'm using "#include <memory>".
Any idea what's breaking the indexer?
You need to set the pre-processor symbol '__GXX_EXPERIMENTAL_CXX0X__' to the eclipse project. g++ automatically adds that when you use '-std=c++0x', but eclipse is not aware of that, so it treats those sections of the relevant headers as disabled.
I experienced this problem under Windows with Eclipse 4.5.1 (Mars.1) and Cygwin 2.3.0 (GCC 4.9.3).
The indexer can't find shared_ptr because of lines like this in the <memory> header. The __cplusplus macro is evaluating to something other than C++ 11 (aka 201103) so the older auto_ptr.h is being included instead of shared_ptr.h. Why? The below screen shot of the project properties shows that C++ 98 (199711) is being detected under CDT GCC Build-in Compiler Settings.
#if __cplusplus >= 201103L
# include <bits/shared_ptr.h>
#else
# include <backward/auto_ptr.h>
#endif
There are two possible solutions to tell Eclipse to use C++ :
On the same Preprocessor Include Paths screen, scroll to the top of the Setting Entries area. Expand CDT User Setting Entries. Add a new Preprocessor Macro for __cplusplus=201103L. Do this for both the Release and Debug Configurations. Then rebuild the index.
If you want to default the CDT GCC Build-in Compiler Settings to use 201103 for all projects, then edit the language.settings.xml file (under Windows this is c:\Users\deanhill\workspace\.metadata\.plugins\org.eclipse.cdt.core\language.settings.xml). Set __cplusplus=201103L. Restart Eclipse and rebuild the index.
Although I am late to the game, this is what worked for me:
Right-Click on Project->Properties->C/C++ General->Preprocessor Include Paths, Macros, etc. --> Click "Providers" tab --> CDT GCC Built-in Compiler Settings
Uncheck "Use global provider shared between projects"
Add -std=c++0x
It will then look something like this:
${COMMAND} ${FLAGS} -E -P -v -dD -std=c++0x "${INPUTS}"
Rebuild index.
Using Debian Jessie + Eclipse Kepler Build id: 20140224-0627
I experienced the same problem. I have added the GXX_EXPERIMENTAL_CXX0X as well as -std=c++11 to compiler options in workspace. However it did not solve my problem.
I was missing one more step:
Right-Click on Project->Properties->C/C++ Build->Settings->Cross G++ Compiler->Miscellaneous->Other flags
I changed
-c -fmessage-length=0
to
-c -fmessage-length=0 -std=c++11
Now Eclipse sees std::shared_ptr and indexes it correctly.
For me it worked by setting other dialect flags = -std=c++11 under:
Preferences -> C++ Build -> Settings -> GCC C++ Compiler -> Dialect,
as well as adding -std=c++11 under:
Preferences -> C++ General -> Preprocessor Include Path -> Providers -> CDT GCC Build-in Compiler Settings -> command to get compiler specs.
Do not forget to clean and rebuild your Project/Index.

Eclipse CDT C++ error

I have just installed Eclipse CDT on my machine for developping C++ applications.
I have created a new C++ project. I have copied a cpp file.
When I click the build button, the project compile without errors.
However, I have a problem. The problem is that Eclipse tell me that there is many errors. For example Eclipse show that "using namespace std" is an error or that "#include " is an error.
I don't know what is the problem with Eclipse because my file compile properly when i click the "build" button.
Is there some settings that I did not set properly?
Thanks!
You need to add the paths to the std libraries to your project in eclipse. It seems that somehow eclipse did not find your std library.
You need to add the path to your gcc include under:
properties->C/C++ General->Paths and Symbols->Includes->GNU C and GNU C++
The paths GCC/G++ uses can be found by the commands in this answer to "Where does gcc look for C and C++ header files?".
Requires a restart of eclipse to be active.
Install the GNU C++ Compiler g++, using the command:
sudo apt-get install g++
In my case (I am using TDM GCC installed on a non-standard location on Windows), I had to add the Path variable to the project. I did it by Project->Properties->C/C++ build->build variables. The value to the Path variables are auto read when one clicks on add and then select Path from the drop down list. Once the Path variable is added the C/C++ index needs to be rebuild.

How to setup GTK+ to develop with Code::Blocks on Ubuntu Linux

I am trying to develop a GTK+ application on Ubuntu 11.4, using Code::Blocks.
www.gtk.org has instructions on building GTK+ from source, that looked complicated. But the Ubuntu package manager listed libgtk3-dev as a package that I installed.
Code::Blocks I installed using the Ubuntu Software Center.
Using the Code::Blocks project wizard to create a GTK+ project, when I build, the project fails to compile "cannot find gtk/gtk.h".
Clearly the GTK include (and lib) folders are not added to the Code::Blocks search folders. I have located the relevant paths and files...
Do I have to explicitly & manually add all the search paths to Code::Blocks' search paths? Or am I missing some installation step.
Assuming that you have located and installed the correct package. As of 2011, the current package was libgtk-3-dev then the pkg-config tool can be used to extract the linker and compiler flags - and with proper escaping in the Code:Blocks settings can inject the correct settings automatically.
Open Code::Blocks Settings > Compiler and Linker Settings... and add the following under Global Compiler Settings > Compiler Settings > Other Options
`pkg-config --cflags gtk+-3.0`
and add this to Global Compiler Settings > Linker Settings > Other Options
`pkg-config --libs gtk+-3.0`
With the ` this has the effect of running the pkg-config tool calling --cflags gtk+-3.0 (or --libs) which, assuming libgtk3-dev is installed, injects the necessary search folders and lib directives onto the gcc command line.
As an alternative, developer.ubuntu.com lists Anjuta as a C/C++ IDE that can create GTK+ projects. As an alternative to Code::Blocks its far more polished as an Ubuntu IDE.
Scratch that. Anjuta looses its sheen quickly.