简体   繁体   English

在 Eclipse CDT 中找不到头文件

[英]Header file not found in Eclipse CDT

I'm trying to build a project that uses an external library (Casablanca) using Eclipse CDT 8.8.1.我正在尝试使用 Eclipse CDT 8.8.1 构建一个使用外部库 (Casablanca) 的项目。 on Mac OS.在 Mac 操作系统上。 As expected, the first build run returned "cpprest/http_client.h file not found" errors.正如预期的那样,第一次构建运行返回“cpprest/http_client.h 文件未找到”错误。

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.然后,我通过右键单击项目,选择 Properties->C/C++ Include Paths and Symbols,Add External Include Path,然后移动它,继续添加包含路径 (/Users/me/projects/casablanca/Release/include)优先作为第一个列出的文件夹。

However this did not solve the problem and Eclipse still can't seem to find the headers.然而,这并没有解决问题,Eclipse 似乎仍然无法找到标题。 The #include directive is as below: #include 指令如下:

#include <cpprest/http_client.h>

and the added /include directory does have a /cpprest sub-directory, with http_client.h in it.并且添加的 /include 目录确实有一个 /cpprest 子目录,其中包含 http_client.h。

Any help would be appreciated.任何帮助,将不胜感激。

Adding an include path to Project Properties | C/C++ General | Paths and SymbolsProject Properties | C/C++ General | Paths and Symbols添加包含路径Project Properties | C/C++ General | Paths and Symbols Project Properties | C/C++ General | Paths and Symbols 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.在索引项目时, Project Properties | C/C++ General | Paths and Symbols仅将包含路径添加到 CDT 的索引器搜索的包含集。

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如果您使用的是托管构建项目(而不是 Makefile 项目)——这听起来像您一样——您将在Project Properties | C/C++ Build | Settings添加包含路径。 Project Properties | C/C++ Build | Settings Project Properties | C/C++ Build | Settings . 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 .请注意,索引器会自动选取构建设置,因此一旦您执行此操作,就不需要将其添加到Paths and Symbols

This answer applies if:此答案适用于:

  1. You do not have a C++ Managed Build Project (for example, you have a C++ Makefile project as I do).您没有 C++ 托管构建项目(例如,您像我一样有 C++ Makefile 项目)。

and

  1. 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 .就我而言,当我将包含目录添加到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.然后按 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.请注意,在此之前,我尝试将包含目录添加到Project Properties > C/C++ General > Paths and Symbols > GNU C++ > Add ,但这并不能单独解决问题。

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.根据一些快速测试,假设您使用的是外部构建系统,似乎没有必要包含Paths and Symbols > GNU C++ > etc

I am using Eclipse 3.8.1 on Ubuntu 16.04 with Eclipse CDT 8.6.0.我在 Ubuntu 16.04 和 Eclipse CDT 8.6.0 上使用 Eclipse 3.8.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM