即使设置了包含路径,Eclipse 也找不到头文件管理器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27905795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse can't find header filers even though include paths have been set
提问by Lundin
When creating a new C project in a particular Eclipse environment which uses GCC, I run into a peculiar linker problem:
在使用 GCC 的特定 Eclipse 环境中创建新的 C 项目时,我遇到了一个特殊的链接器问题:
Fatal error: my_header.h: No such file or directory.
致命错误:my_header.h:没有这样的文件或目录。
I get this problem since "my_header.h" resides in a sub folder. After investigation, I found out that you need to include sub folders in the GCC include path (option -I
). How this is done seems to vary between different Eclipse implementations, but it should be something like
我遇到这个问题,因为“my_header.h”驻留在子文件夹中。经过调查,我发现您需要在 GCC 包含路径中包含子文件夹(选项-I
)。这是如何完成的似乎在不同的 Eclipse 实现之间有所不同,但它应该类似于
Project -> Properties -> C/C++ Build -> Settings -> Compiler -> Includes
项目 -> 属性 -> C/C++ 构建 -> 设置 -> 编译器 -> 包含
Where "compiler" may have a different name in different implementations, and "includes" may be called "input" or similar.
其中“编译器”在不同的实现中可能有不同的名称,而“包含”可能被称为“输入”或类似名称。
There should be an option to add the include path (option -I
) where you can set the path relative to the specific project, by clicking an "Add" icon followed by Workspace button, then select the directory. Eclipse then generates a path, which should look something like
应该有一个选项可以添加包含路径(选项-I
),您可以在其中设置相对于特定项目的路径,方法是单击“添加”图标,然后单击工作区按钮,然后选择目录。Eclipse 然后生成一个路径,它应该看起来像
"${workspace_loc:/${ProjName}/app}"
"${workspace_loc:/${ProjName}/app}"
Do this for all sub folders in the project (and their sub folders).
对项目中的所有子文件夹(及其子文件夹)执行此操作。
But despite doing the above for the relevant folder, I still get the "no such file or directory" error. What could be the problem?
但是尽管对相关文件夹执行了上述操作,我仍然收到“没有这样的文件或目录”错误。可能是什么问题呢?
(I'm posting this Q&A style since I want to share the solution of this problem with others)
(我发布这个问答风格是因为我想与其他人分享这个问题的解决方案)
回答by Lundin
The reason for this error is that there is no sanity check for the gcc include path. Despite giving a relative path to Eclipse as described, Eclipse will still pass an absolute path to gcc -I
.
此错误的原因是没有对 gcc 包含路径进行完整性检查。尽管如所述提供了 Eclipse 的相对路径,但 Eclipse 仍会将绝对路径传递给 gcc -I
。
Suppose you have your project located at a path like:
假设您的项目位于如下路径:
C:\???\workspace\project
and the sub folder located at
和位于的子文件夹
C:\???\workspace\project\std
where "???" is any string containing any non-standard ASCII letters. In this example I used Swedish, but you'll encounter such non-standard letters in most languages (French, German, Spanish etc).
在哪里 ”???” 是包含任何非标准 ASCII 字母的任何字符串。在此示例中,我使用了瑞典语,但您会在大多数语言(法语、德语、西班牙语等)中遇到此类非标准字母。
The problem is that Eclipse passes the full path, rather than the relative one to GCC, and then there is some sort of symbol table mishap. So rather than getting the expected
问题是 Eclipse 将完整路径而不是相对路径传递给 GCC,然后出现某种符号表故障。所以而不是得到预期
-I"C:\???\workspace\project\std"
you might get random garbage letters such as:
您可能会收到随机的垃圾信,例如:
-I"C:\@!#\workspace\project\std"
The path doesn't make sense and the include path is not sanity checked, so you get no diagnostic telling you about this, unless you read the console output in detail. Instead, Eclipse silently pretends that it has added your include path to the list of paths it should check, even though it has not.
该路径没有意义,并且包含路径没有经过健全性检查,因此除非您详细阅读控制台输出,否则您不会得到任何诊断信息。相反,Eclipse 会默默地假装它已将您的包含路径添加到它应该检查的路径列表中,即使它没有。
The only solution seems to be avoiding placing your projects below paths that contain non-ASCII letters. It would seem that this is a bug in several implementations of Eclipse that use GCC.
唯一的解决方案似乎是避免将您的项目放在包含非 ASCII 字母的路径下。这似乎是使用 GCC 的 Eclipse 的几个实现中的一个错误。