【问题标题】:include local path in project c++ but building failed?在项目 C++ 中包含本地路径但构建失败?
【发布时间】:2015-05-26 01:14:35
【问题描述】:

我在 Eclipse,ubuntu 中有一个 c++ 项目。结构项目同:

HelloWorld
   - Includes (i had include path: HelloWorld/sources/diagcom)
   - sources
      - diagcom 
        + diagcom.hpp
        + diagcom.cpp
   - main.cpp

我将路径 HelloWorld/sources/diagcom 包含到 Includes 中,并且在 main.cpp 中包含:

#include <diagcom.hpp>
int main(void) {
    return 0;
}

但我在构建项目时遇到错误

"fatal error: diagcom.hpp: No such file or directory"

那么 main.cpp 文件有什么问题。如果我在 #include &lt;diagcom.hpp&gt; 上按住 Ctrl+单击鼠标,diagcom.hpp 文件将在 eclipse 上打开??

【问题讨论】:

  • 是错字吗? diagcom.hppdiacom.hpp
  • @R Sahu。对不起,我打错了。

标签: c++ eclipse ubuntu


【解决方案1】:

使用

#include "diacom.hpp"

而不是

#include <diacom.hpp>

带引号的版本是针对项目包含文件的,这些文件会在指定的包含路径以及源文件本身的目录中搜索。

带尖括号的版本用于系统头文件。将在适当的系统头目录中搜索这些文件。哪些目录是“合适的”取决于系统;答案可能取决于其他编译器选项,尤其是标准版本,但您不必担心。

使用两种不同的语法实际上对人类读者也很有帮助,因为您可以一眼看出包含是否是标准库包含。

【讨论】:

  • 我曾尝试使用#include "diagcom.hpp" 但我仍然遇到同样的错误。如果我使用#include "sources/diagcom/diagcom.hpp",构建成功
  • sources/diagcom 在您的包含目录列表中吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-19
  • 1970-01-01
  • 2019-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多