Header file not found in Eclipse CDT - c++

I'm trying to build a project that uses an external library (Casablanca) using Eclipse CDT 8.8.1. on Mac OS. As expected, the first build run returned "cpprest/http_client.h file not found" errors.
I then proceeded to add an include path (/Users/me/projects/casablanca/Release/include) by right-clicking on the project, selecting Properties->C/C++ Include Paths and Symbols, Add External Include Path, and moving it up in priority as the first listed folder.
However this did not solve the problem and Eclipse still can't seem to find the headers. The #include directive is as below:
#include <cpprest/http_client.h>
and the added /include directory does have a /cpprest sub-directory, with http_client.h in it.
Any help would be appreciated.

Adding an include path to Project Properties | C/C++ General | Paths and Symbols only adds the include path to the set of includes searched by CDT's indexer when indexing the project.
The actual build system needs to be told the include path by another means. If you're using a Managed Build project (as opposed to a Makefile project) - which it sounds like you are - you would add the include path in Project Properties | C/C++ Build | Settings. Note that the indexer automatically picks up build settings, so once you do this, there shouldn't be a need to also add it to Paths and Symbols.

This answer applies if:
You do not have a C++ Managed Build Project (for example, you have a C++ Makefile project as I do).
and
Various things in the code editor are underlined in red because a header file is not detected.
In my case, the indexer found the headers (and all the red underlines went away) when I added the include directories to Project Properties > C/C++ General > Preprocessor Includes > Select GNU C++ > Select CDT User Settings Entries > Press Add. Make sure the combo boxes (aka drop down menus) are set to "Include Directory" and "File System Path". Type in or browse for the include directory. Then press OK > OK.
Note that prior to this I tried adding the include directory to Project Properties > C/C++ General > Paths and Symbols > GNU C++ > Add, but this did not solve the problem alone.
Based on some quick testing it seems that the Paths and Symbols > GNU C++ > etc includes are unnecessary assuming you are using an external build system.
I am using Eclipse 3.8.1 on Ubuntu 16.04 with Eclipse CDT 8.6.0.

Related

Eclipse CDT: Fatal Error. No Such File or Directory [duplicate]

I'm trying to build a project that uses an external library (Casablanca) using Eclipse CDT 8.8.1. on Mac OS. As expected, the first build run returned "cpprest/http_client.h file not found" errors.
I then proceeded to add an include path (/Users/me/projects/casablanca/Release/include) by right-clicking on the project, selecting Properties->C/C++ Include Paths and Symbols, Add External Include Path, and moving it up in priority as the first listed folder.
However this did not solve the problem and Eclipse still can't seem to find the headers. The #include directive is as below:
#include <cpprest/http_client.h>
and the added /include directory does have a /cpprest sub-directory, with http_client.h in it.
Any help would be appreciated.
Adding an include path to Project Properties | C/C++ General | Paths and Symbols only adds the include path to the set of includes searched by CDT's indexer when indexing the project.
The actual build system needs to be told the include path by another means. If you're using a Managed Build project (as opposed to a Makefile project) - which it sounds like you are - you would add the include path in Project Properties | C/C++ Build | Settings. Note that the indexer automatically picks up build settings, so once you do this, there shouldn't be a need to also add it to Paths and Symbols.
This answer applies if:
You do not have a C++ Managed Build Project (for example, you have a C++ Makefile project as I do).
and
Various things in the code editor are underlined in red because a header file is not detected.
In my case, the indexer found the headers (and all the red underlines went away) when I added the include directories to Project Properties > C/C++ General > Preprocessor Includes > Select GNU C++ > Select CDT User Settings Entries > Press Add. Make sure the combo boxes (aka drop down menus) are set to "Include Directory" and "File System Path". Type in or browse for the include directory. Then press OK > OK.
Note that prior to this I tried adding the include directory to Project Properties > C/C++ General > Paths and Symbols > GNU C++ > Add, but this did not solve the problem alone.
Based on some quick testing it seems that the Paths and Symbols > GNU C++ > etc includes are unnecessary assuming you are using an external build system.
I am using Eclipse 3.8.1 on Ubuntu 16.04 with Eclipse CDT 8.6.0.

Why does Eclipse mark pseudo-errors in my source?

I have locally forked (via hg clone) a C/C++ (Eclipse CDT) project and imported it into my Eclipse workspace. My editor window for the forked project now looks like this:
Clearly, these are not real errors, since the code builds correctly. Also, these errors are not marked in the original project from which this one was forked.
Why does Eclipse think there are errors in this source?
EDIT: Eclipse error messages when hovering over the "bugs" are, e.g., Type int64_t could not be resolved and symbol 'cout' could not be resolved.
EDIT: I've noticed that Eclipse usually shows a "folder" named includes in the project. It is missing for this project. How can I get it back?
Eclipse has to know the paths where to find the include files. This may be set using general eclipse settings or project by project.
For some reason it seems like the default paths are not set for your current project.
What you can do:
Open the project settings and go to C/C++ General -> Paths and Symbols (at least that is how it is called in my eclipse version) and fix the include directories.
Maybe it is enough to load the default configuration for that specific project. Maybe you have to set up your include pathes by yourself. On Unix / OS X this should usually be usr/include. On Windows I have no idea, but that should be easy to find out.
Afterwards it may be necessary that your rebuild your eclipse index (right click on your project, then index -> rebuild).
If that does not help please share a screenshot of the Paths and Symbols dialog of your project.
Also see the eclipse documentation on this topic.
I had to include
CDT Cross GCC Built-in Compiler Settings
CDT GCC Built in Compiler Settings [ Shared ]
in Properties for the project -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Providers
add this define in Eclipse to Project Properties->C/C++ General->Paths and Symbols
__STDC_FORMAT_MACROS
Rebuild your eclipse index. It will work.
This worked on Mac OS X Yosemite 10.10.5, Eclipse version Mars.1 Release (4.5.1):
Since the includes are usually discovered by Eclipse through the toolchain, check that you have an actual toolchain set (when I ran into this problem after importing a project, the toolchain was set to "No toolchain."):
Project -> Properties -> C/C++ Build -> Tool Chain Editor -> Current toolchain
If no toolchains appear in the dropdown, try unchecking "Display compatible toolchains only" and choosing a toolchain (I chose Cross GCC). When I saved the changes and re-opened the project properties to look at this field again, "Display compatible toolchains only" was automatically re-checked.
Then re-index the project:
Project -> C/C++ Index -> Rebuild
This solved the problem for me (the "pseudo-errors" disappeared, and the includes "folder" appeared under my project in the file system view).
Have you #included the correct files in your code? For std::cout it would be:
#include <iostream>
and for int64_t:
#include stdint.h

Eclipse C++: Symbol 'std' could not be resolved

I am getting this error in the TestExecute.cpp -
"Symbol 'std' could not be resolved"
CODE
#include <iostream>
using namespace std;
I just created a executable project in Eclipse (in Windows 7) as shown below. It seems like I am selecting a toolchain that is not supported. Is it so? I have installed Cygwin and it is available in preferences.
EDIT: Based on #RobertoWilko comment, removing the line "using namespace std;
" removed the error. But the binary is not created. "Launch Failed. Binary not found". How to correct this?
Try out this step: https://www.eclipse.org/forums/index.php/t/636348/
Go to
Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers
Activate CDT GCC Built-in Compiler Settings
Deactivate Use global provider shared between projects
Add the command line argument -std=c++11.
I do not know whether you have solved this problem but I want to post my solution for those might ran into the same problem.
First, make sure that you have the "Includes" folder in your Project Explorer. If you do not have it, go to second step. If you have it, go to third step.
Second, Window -> Preferences-> C/C++- > Build >Environment: Create two environment variables:
a) Name: C_INCLUDE_PATH Value: /usr/include
b) Name: CPLUS_INCLUDE_PATH Value: /usr/include/c++
Go to Cygwin/usr/include/, if you cannot find folder "c++", copy it from \cygwin\lib\gcc\i686-pc-cygwin\X.X.X\include and Then restart your Eclipse.
Third, Right Click your project in Project Explorer -> Properties -> C/C++ General -> Paths and Symbols -> Includes -> Languages:GNU C++
If you can find some C++ folders in the "Include directories" then click Apply and OK. Change a bit your codes, and save it.
You will find there will be not symbol could not be resolved problems.
I documented my solution, hoping someone might get benefits.
You can rewrite the code likes this:
#include<iostream>
#include<stdio.h>
using namespace std;
For MinGW this worked for me:
Right click project, select Properties
Go to C/C++ General - Paths and Symbols - Includes - GNU C++ - Include directories
Select Add...
Select Variables...
Select MINGW_HOME and click OK
Click Apply and OK
You should now see several MinGW paths in Includes in your project explorer.
The errors may not disappear instantly, you may need to refresh/build your project.
If you are using Cygwin, there could be an equivalent variable present.
The includes folder in the project is probably missing /usr/include/c++.
Goto your project in project explorer, right click -> Properties -> C\C++ Build -> Environment -> add -> value= /usr/include/c++. Restart eclipse.
What allowed me to fix the problem was going to: Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers -> CDT GCC built-in compiler settings, enabling that and disabling the CDT Cross GCC Built-in Compiler Settings
Install C++ SDK:
Help > Install New Software > Work with: path for your eclipse version > search for C++ and install C++ sdk development tools.
Example for a path: Mars - http://download.eclipse.org/releases/mars
I was having this problem using Eclipse Neon on Kubuntu with a 16.04 kernel, I had to change my #include <stdlib.h> to #include <cstdlib> this made the std namespace "visible" to Eclipse and removed the error.
This worked for me on Eclipse IDE for C/C++ Developers Version: 2020-03 (4.15.0) Build id: 20200313-1211. Also, my code is cross-compiled.
Create a new project making sure it's created as a cross-compiled solution. You have to add the /usr/bin directory that matches your cross-compiler location.
Add the C and C++ headers for the cross-compiler in the Project Properties.
For C: Project > Properties > C/C++ General > Paths and Symbols > Includes > GNU C. Add... -> The path to your /usr/include directory from your cross-compiler.
For C++: Project > Properties > C/C++ General > Paths and Symbols > Includes > GNU C++. Add... -> The path to your /usr/include/c++/ directory from your cross-compiler.
If you don't know your gcc version, type this in a console (make sure it's your cross gcc binary):
gcc -v
Modify the dialect for the cross-compilers (this was the trick).
For C: Project > Properties > C/C++ Build > Settings > Tool Settings > Cross GCC Compiler > Dialect. Set to ISO C99 (-std=C99) or whatever fits your C files standard.
For C++: Project > Properties > C/C++ Build > Settings > Tool Settings > Cross G++ Compiler > Dialect. Set to ISO C++14 (-std=c++14) or whatever fits your C++ files standard.
If needed, re-index all your project by right-clicking the project > Index > Rebuild.
The problem you are reporting seems to me caused by the following:
you are trying to compile C code and the source file has .cpp extension
you are trying to compile C++ code and the source file has .c extension
In such situation Eclipse cannot recognize the proper compiler to use.
Try restart Eclipse first, in my case I change different Compiler setting of the project then it shows this message, after restart it works.

How do I include a statically linked library in my Eclipse C++ project?

I have an open-source library that's distributed in source form. After I run the Makefile, I end up with a .h file and a .a file that I then want to include in a project that I'm working on. I'm familiar with how I can add these by editing a Makefile manually or by invoking the compiler from the command line, but I'm not sure how I can add these to my Eclipse C++ project, created using the CDT.
I'm currently using Eclipse Indigo. I found some instructions for older versions of Eclipse, but the menus aren't what are described. I poked around a bit, and didn't see anything familiar.
right click on the project name in the project explorer with the project being opened, select project properties. Then select C/C++ General -> Paths and Symbols -> includes -> GNU C++ and add the path to your header file. You should do the same for you library under : C/C++ General -> Paths and Symbols -> Libraries -> Add , and add your library file path.
How do I add an external library to my C++ project?
Go to Your Project's Properties by right clicking on project's name and selecting properties. Click on "C/C++ Build". Under Settings->Tool Settings Tab, click on GCC C Linker / Libraries. Then add a library and a search path.

Eclipse C++ include error: no such file or directory

I've loaded a C++ project into Eclipse (Europa) and I'm familiarizing myself with the CDT interface.
There is one particularly annoying error message for the following line:
#include "somedir/somefile.h"
somedir/somefile.h: No such file or directory
The include file exists in "/opt/local/project/include/somedir/somefile.h".
Under Project > Properties > C/C++ General > Paths and Symbols > Includes, I've already added the include directory "/opt/local/project/include".
However, this does not seem to solve the issue.
Does anyone know how to deal with this error?
Thanks.
Edit:
Solved the problem. Turns out that it was a simple issue. I had to "refresh" all the projects in the workspace.
Why such an old version? Newer versions of the Eclipse CDT have made vast improvements.
This is a really obvious question, but under Project > Properties > C/C++ General > Paths and Symbols > Includes (at least in the current CDT), there are separate categories for each language (assembly, C, and C++). Did you make sure to add /opt/local/project/include under both C and C++ (if appropriate)?
Alternatively, if your project is built using Make, then simply building your project from within Eclipse will often let Eclipse auto-detect include directories using Make's output, without your having to set the include paths yourself.
If the paths are all set up correctly, then the standard fix for indexing-related problems is to right-click on your project, choose Index, and choose Rebuild.
Right Click on project -> Index -> Freshen All Files.