问题
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.
回答1:
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
.
回答2:
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.
来源:https://stackoverflow.com/questions/37935535/header-file-not-found-in-eclipse-cdt