c++ - 除非使用完整的相对路径,否则 Eclipse CDT 无法找到包含文件

标签 c++ eclipse include eclipse-cdt

我已经使用 Eclipse 一段时间了,这让我受阻了。几周前我创建了一个名为 ITS8410_LIB 的库,然后在我处理一个名为 Reach_Lib 的支持库时将其搁置。该目录包括我在第一次创建项目时添加回来的路径,效果很好。今天完成了Reach_Lib,去把它的路径添加到ITS8410_Lib。我使用项目属性 C++ 设置来添加工作区路径(就像我之前做过很多次一样)。我只有一个构建配置。该路径显示在图像中(以蓝色突出显示的那个是我在这个问题中谈论的特定路径)。

enter image description here 当我将文件包含在源代码中时,Eclipse(我看到黄色问号)和编译器(我收到编译器错误)都无法找到该文件。如果我使用完整的绝对路径语法添加目录路径,结果是相同的。我可以修改源代码并通过当前目录的完整相对路径指定#include,然后找到它。 Eclipse 不会使用项目设置中指定的路径。同样的 Reach_Lib 有一个关联的单元测试项目,路径是从那里的工作空间设置指定的,它工作正常。

enter image description here

今天之前添加的目录路径看起来没问题。我今天添加的路径(有两个显示此行为的库)似乎被忽略了。我查看了编译器设置(见下图),指定给编译器的路径似乎没问题。

enter image description here

在 Windows7 64 位下运行(但使用 32 位版本的 Eclipse Indigo)。 我试过:

  1. 重建索引
  2. 多次退出并重新启动 Eclipse
  3. 工作区和绝对文件路径
  4. 修改包含路径的顺序
  5. 项目中不同的.h包含文件

更新

我查看了 .cproject 文件,虽然我不太了解这些文件应该是什么样子,但我认为我遇到了问题。也许问题是:如何告诉 Eclipse 重建 .cproject 文件?我似乎有两个相似的部分,Eclipse 变得很困惑。我可以看到标记为后缀的不同版本号。在我看来,可视化编辑器让我修改一个部分,但 IDE 和编译器只关心另一部分。这是相关部分

...

                <folderInfo id="nbeclipse.toolchain.nbl.rel.396284009." name="/" resourcePath="">
                    <toolChain id="nbeclipse.toolchain.nbl.rel.tc.1465290409" name="NetBurner Device Library" superClass="nbeclipse.toolchain.nbl.rel.tc">
                        <targetPlatform id="nbeclipse.toolchain.nbl.rel.tc.targetPlatform.283367649" isAbstract="false" name="NetBurner Module Library" superClass="nbeclipse.toolchain.nbl.rel.tc.targetPlatform"/>
                        <builder buildPath="${workspace_loc:/ITS8410_Lib/Release}" id="nbeclipse.toolchain.nbl.rel.tc.builder.2064025940" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Release ELF builder (MINGW)" superClass="nbeclipse.toolchain.nbl.rel.tc.builder"/>
                        <tool id="nbeclipse.toolchain.nbl.rel.tc.gcc.278195048" name="GNU C Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc">
                            <inputType id="nbeclipse.toolchain.nbl.rel.tc.gcc.input.1060035859" name="GNU C Input" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc.input"/>
                        </tool>
                        <tool id="nbeclipse.toolchain.nbl.rel.tc.gpp.767008127" name="GNU C++ Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gpp">
                            <option id="nbeclipse.toolchain.super.gcc.directories.includepaths.1666029541" name="Include paths (-I)" superClass="nbeclipse.toolchain.super.gcc.directories.includepaths" valueType="includePath">
                                **inside here is an option list with all my include paths**
                    ...
                </folderInfo>

然后在 folderInfo 关闭标签之后另一个 folderInfo 部分开始

                <folderInfo id="nbeclipse.toolchain.nbl.rel.396284009.2022231003" name="/" resourcePath="src">
                    <toolChain id="nbeclipse.toolchain.nbl.rel.tc.1982112905" name="NetBurner Device Library" superClass="nbeclipse.toolchain.nbl.rel.tc" unusedChildren="">
                        <targetPlatform id="nbeclipse.toolchain.nbl.rel.tc.targetPlatform" isAbstract="false" name="NetBurner Module Library" superClass="nbeclipse.toolchain.nbl.rel.tc.targetPlatform"/>
                        <tool id="nbeclipse.toolchain.nbl.rel.tc.gcc.1671008421" name="GNU C Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc.278195048">
                            <inputType id="nbeclipse.toolchain.nbl.rel.tc.gcc.input.436341699" name="GNU C Input" superClass="nbeclipse.toolchain.nbl.rel.tc.gcc.input"/>
                        </tool>
                        <tool id="nbeclipse.toolchain.nbl.rel.tc.gpp.498310867" name="GNU C++ Compiler" superClass="nbeclipse.toolchain.nbl.rel.tc.gpp.767008127">

                            **the newly added paths don't show up here, if I add them manually things start working** 

最佳答案

答案的关键是由 dbrank0 发布的,但他没有将其提升为答案,所以我只是对评论投了赞成票。 .cproject 文件出了点​​问题,手动编辑解决了这个问题。

关于c++ - 除非使用完整的相对路径,否则 Eclipse CDT 无法找到包含文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12399994/

相关文章:

c++ - 如何在 c++ 的 quickfixc 中动态地就 SenderCompID 和 TargetCompID 达成一致?

c++ - 变量赋值

c++ - 需要当前进程的 PID,getpid() 返回 -1

c++ - eclipse C++。包含带有类的 .h 文件。 "Symbol ' [类 ]' could not be resolved"

c++ - 模板函数的歧义递归定义

android - 无法使用多部分实体上传视频文件

eclipse - 无法访问您的 SonarQube 服务器之一。请检查您的连接设置

c++ - C++ 的头文件和源文件组织

javascript - 如何处理两个单独文件中的异步?

C++ 包含 header 约定