Eclipse C/C++ (CDT) import files into project - header file not found - include path

46,170

Solution 1

  1. Right click on the project and select properties.
  2. Select C/C++ General -> Path and Symbols.
  3. Select Includes tab.
  4. In Languages list, select 'GNU C' or whatever C compiler tool chain you use.
  5. Press 'Add...' button and add the directory for the include files.
  6. Close Properties window and rebuild. You should see new path being used as -I in build process.

Solution 2

None of what I have found so far helped, among other things adding the include path in the following places did not work for me:

  • Project -> Properties -> C/C++General -> Paths and Symbols -> Includes tab -> GCC C
  • Project -> Properties -> C/C++General -> Paths and Symbols -> Includes tab -> GCC C++
  • Project -> Properties -> C/C++build -> Settings: Tool settings tab -> GCC C++ Compiler -> includes
  • Project -> Properties -> C/C++build -> Settings: Tool settings tab -> GCC C Compiler -> includes

However, adding the include path to:

Project -> properties -> C/C++General -> Paths and Symbols -> Includes tab -> Assembly

while checking 'add to all languages' did work.

Strangely enough this last option does all the above - why they do not work on their own is not really clear to me.

This is assuming that you do not use makefile. If you do then you can forget about changes as listed above. Eclipse will find automagically where all needed input is by analyzing compiler logs. I thought this is magic but it works the following way:

  • Build All from project menu - even if that succeeded it may leave some of your files marked with 'faults' because of unknown symbols and such so you have to go for step two:
  • update the index: from project window you right click and chose "Properties -> Index -> Rebuild. If the project is big you will see progress in lower right corner of eclipse window.

I think above process can be done in different ways and eclipse can do it all by itself too but for large projects I found manual handling as described above less distracting.

Solution 3

Alt + Enter for opening Properties.

Open C/C++ General -> Paths and Symbols -> Includes -> Add...

Note that sometimes you need to choose "Is a workspace path" (ex: for linked folder).

Share:
46,170
eat_a_lemon
Author by

eat_a_lemon

Updated on October 27, 2020

Comments

  • eat_a_lemon
    eat_a_lemon over 3 years

    I am trying to import files into an Eclipse C project and compile it. The build process cannot find the local header files. The header files are located in the src directory. How can I edit the include path in eclipse? If I were doing it manually I could specify the -I option in gcc.

    Building file: ../src/averaging.c
    Invoking: GCC C Compiler
    gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/averaging.d" -MT"src/averaging.d" -o"src/averaging.o" "../src/averaging.c"
    ../src/averaging.c:2:23: fatal error: averaging.h: No such file or directory
    compilation terminated.
    make: *** [src/averaging.o] Error 1
    
  • eat_a_lemon
    eat_a_lemon over 12 years
    Hi thanks for the answer. It is still not picking up the include path after I added it.
  • eat_a_lemon
    eat_a_lemon over 12 years
    No. I added the path to assembly source and the -I is still not there when i build all.
  • eat_a_lemon
    eat_a_lemon over 12 years
    Nevermind I added it to assembly source instead of GNU C. Thank you for the help.
  • eat_a_lemon
    eat_a_lemon over 12 years
    Do you know what assembly source means?
  • Kamyar Souri
    Kamyar Souri over 12 years
    your code can be mix of C files and assembly files. an assembler is used to compile that to machine code. if you make a change to assembly source settings, it only affects assembly files compilation.
  • TRoa
    TRoa over 5 years
    Very old but still useful. Thanks buddy. One point please. I had to add links to all the file one by one. But in original project, it was picking up links automatically. Why is that so? Is there any path or link that I should refresh or include in order to make this work. Including paths for every individual header file seems like a bit of an over kill.
  • Technophile
    Technophile over 5 years
    If you have conflicting settings under Assembly vs. C/C++: I suspect that the Indexer first parses those include files using those settings - which sets include guard variables! Then when it processes for C/C++, the include guards are already set, so you don''t see what you expected.