Eclipse can't find header filers even though include paths have been set

别说谁变了你拦得住时间么 提交于 2019-12-17 20:52:43

问题


When creating a new C project in a particular Eclipse environment which uses GCC, I run into a peculiar linker problem:

Fatal error: my_header.h: No such file or directory.

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

Project -> Properties -> C/C++ Build -> Settings -> Compiler -> Includes

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

"${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)


回答1:


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.

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).

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

-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.

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.



来源:https://stackoverflow.com/questions/27905795/eclipse-cant-find-header-filers-even-though-include-paths-have-been-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!