Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

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

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:???workspaceproject

and the sub folder located at

C:???workspaceprojectstd

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:???workspaceprojectstd"

you might get random garbage letters such as:

-I"C:@!#workspaceprojectstd"

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...