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

末鹿安然 提交于 2019-12-18 13:29:59

问题


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

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



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




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




回答4:


1.Click on your source folder

2.Select 'New'

3.Next select 'Header File'

4.Give a proper name with ".h" extension(For example : header.h)

5.Then select 'Finish'

6.Then create your function

7.Save your "header.h" file

8.Then select 'Project' from the top of the console

9.Select 'Build All'

10.Then open your ".c" file

11.Write #include"header(see step 4).h" to use the header file

12.Follow step 7 to 9

13.Then click on 'Run' from the top of the console



来源:https://stackoverflow.com/questions/8477974/eclipse-c-c-cdt-import-files-into-project-header-file-not-found-include

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