繁体   English   中英

“致命错误 C1083:无法打开包含文件”但我已将目录添加到项目

[英]“Fatal error C1083: Cannot open include file” but I have added directory to project

我认为这是一个奇怪的问题。 我会尽量提供尽可能多的细节。 我正在尝试使用以下方法为 Visual Studio 2012 测试项目中的自定义类导入标头:

#include "detector.h"

并且我收到错误

致命错误 C1083:无法打开包含文件:'detector.h':没有这样的文件或目录

我在Project -> Properties -> C/C++ -> General -> Additional Include Directories了头文件所在文件夹的完整路径。

头文件很长,但基本上只包含类的声明。 detector.cpp文件包含类的定义。 我的文件系统上的目录结构如下所示:

project_directory/
  - test/
    - [my_test_project]
  - detector_directory/
    - detector.h
    - detector.cpp
  - other_component_directory/
    - other_component.h
    - other_component.cpp
  ...

#include other_component.h写字,该类执行测试。 我实际上能够包含其他三个类并为所有三个类编写和执行测试,但是四个类(包括detector )给了我同样的错误。

整个project_directory/是从一个 SVN 存储库中检出的,到目前为止只有我贡献过。 我提到,如果链接或为回购创建的东西可能会发生一些奇怪的事情。 我认为在将 repo 恢复到以前的更新后可能会出现这个问题,但不确定我是否只是注意到它。

谢谢你的帮助!

我已经在 Project -> Properties -> C/C++ -> General -> Additional Include Directories 下包含了头文件的完整路径

它应该是detector.h头文件所在的目录路径,而不是文件路径。

检查您是否为活动解决方案配置设置了此选项。 有时它设置为Debug ,但不设置为ReleaseRelease配置在这种情况下无法构建。

我今天为一个类似的问题挠了大约 3 个小时。 就我而言,有一个用于构建二进制文件的构建文件层次结构。 我必须包含我的头文件的目录(在您的情况下为detector.h .h)作为目录和项目级别 Makefile 中的依赖项。

project_directory/
- **libraries.mk**
- test/
- [my_test_project]
  - detector_directory/
    - **build.mk**
    - detector.h
    - detector.cpp
  - other_component_directory/
    - other_component.h
    - other_component.cpp

我必须添加build.mklibraries.mk的路径。

哼!

暂无
暂无

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

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