Eclipse cannot find header files even if paths are included.

When creating a new C project in a specific Eclipse environment using GCC, I run into a specific linker issue:

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

I am getting this problem since "my_header.h" is in a subfolder. After researching, it turned out that you need to include sub folders in the GCC include path (optional -I

). How this is done seems to vary between different Eclipse implementations, but it should be something like

Project -> Properties -> C / C ++ Build -> Preferences -> 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 an include path (optional -I

) where you can set the path relative to a specific project by clicking the Add icon and then the Workspace button then select a directory. Then Eclipse generates a path that should look something like this:

"${workspace_loc:/${ProjName}/app}"

Do this for all sub-folders in the project (and their sub-folders).

But, despite what you did above for the corresponding folder, I still get the error "no such file or directory". What could be the problem?


(I am posting this Q&A style as I want to share a solution to this problem with others)

+3


source to share


1 answer


The reason for this error is the lack of a health check for the gcc include path. Despite providing a relative path to Eclipse as described, Eclipse will still have an absolute path to gcc -I

.

Suppose your project is on the path, for example:

C:\åäö\workspace\project

      

and the subfolder is located at

C:\åäö\workspace\project\std

      

where "åäö" is any string containing any non-standard ASCII letters. In this example, I used Swedish, but you will encounter such non-standard letters in most languages ​​(French, German, Spanish, etc.).



The problem is that Eclipse passes the full path, not the relative one, to GCC, and then some error occurs in the table of tables. So instead of getting the expected

-I"C:\åäö\workspace\project\std"

      

you can get random junk letters like:

-I"C:\@!#\workspace\project\std"

      

The path is meaningless and the included path has not been tested to work, so you won't get any diagnostics telling you about it unless you read the verbose console output. Instead, Eclipse tacitly pretends to add its include path to the list of paths it should check, even if it doesn't.

The only solution does not seem to allow you to place your projects below paths containing non-ASCII letters. It would appear to be a bug in several Eclipse implementations that use GCC.

+4


source







All Articles