Eclipse C/C++ (CDT)将文件导入项目头文件——未找到——包含路径

时间:2023-01-13 20:23:17

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.

我正在尝试将文件导入到Eclipse C项目中并编译它。构建过程无法找到本地头文件。头文件位于src目录中。如何编辑eclipse中的include路径?如果我手工操作,我可以在gcc中指定-I选项。

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

2 个解决方案

#1


15  

  1. Right click on the project and select properties.
  2. 右键单击项目并选择properties。
  3. Select C/C++ General -> Path and Symbols.
  4. 选择C/ c++ General ->路径和符号。
  5. Select Includes tab.
  6. 选择包括选项卡。
  7. In Languages list, select 'GNU C' or whatever C compiler tool chain you use.
  8. 在语言列表中,选择“GNU C”或您使用的任何C编译器工具链。
  9. Press 'Add...' button and add the directory for the include files.
  10. 按“添加…按钮并添加包含文件的目录。
  11. Close Properties window and rebuild. You should see new path being used as -I in build process.
  12. 关闭属性窗口并重新构建。您应该看到在构建过程中使用的新路径。

#2


3  

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
  • 项目->属性-> C/C+ General ->路径和符号->包括tab -> GCC C
  • Project -> Properties -> C/C++General -> Paths and Symbols -> Includes tab -> GCC C++
  • 项目->属性-> C/ c++ General ->路径和符号->包括tab -> GCC c++
  • Project -> Properties -> C/C++build -> Settings: Tool settings tab -> GCC C++ Compiler -> includes
  • 项目->属性-> C/ c++构建->设置:工具设置选项卡-> GCC c++编译器->包括
  • Project -> Properties -> C/C++build -> Settings: Tool settings tab -> GCC C Compiler -> includes
  • 项目->属性-> C/ c++构建->设置:工具设置选项卡-> GCC C编译器->包括

However, adding the include path to:

但是,添加包含路径到:

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

项目->属性-> C/ c++ General ->路径和符号->包括tab ->组装

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:

这是假设您不使用makefile。如果您这样做了,那么您可以忘记上面列出的更改。Eclipse将通过分析编译器日志自动找到所有需要的输入。我认为这很神奇,但它是这样运作的:

  • 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.
  • 更新索引:从项目窗口右键单击并选择“属性->索引->重建”。如果项目很大,您将在eclipse窗口右下角看到进度。

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.

我认为上面的过程可以用不同的方式来完成,eclipse也可以自己完成,但是对于我发现的手动处理的大型项目来说,上面所描述的操作不会让人分心。

#1


15  

  1. Right click on the project and select properties.
  2. 右键单击项目并选择properties。
  3. Select C/C++ General -> Path and Symbols.
  4. 选择C/ c++ General ->路径和符号。
  5. Select Includes tab.
  6. 选择包括选项卡。
  7. In Languages list, select 'GNU C' or whatever C compiler tool chain you use.
  8. 在语言列表中,选择“GNU C”或您使用的任何C编译器工具链。
  9. Press 'Add...' button and add the directory for the include files.
  10. 按“添加…按钮并添加包含文件的目录。
  11. Close Properties window and rebuild. You should see new path being used as -I in build process.
  12. 关闭属性窗口并重新构建。您应该看到在构建过程中使用的新路径。

#2


3  

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
  • 项目->属性-> C/C+ General ->路径和符号->包括tab -> GCC C
  • Project -> Properties -> C/C++General -> Paths and Symbols -> Includes tab -> GCC C++
  • 项目->属性-> C/ c++ General ->路径和符号->包括tab -> GCC c++
  • Project -> Properties -> C/C++build -> Settings: Tool settings tab -> GCC C++ Compiler -> includes
  • 项目->属性-> C/ c++构建->设置:工具设置选项卡-> GCC c++编译器->包括
  • Project -> Properties -> C/C++build -> Settings: Tool settings tab -> GCC C Compiler -> includes
  • 项目->属性-> C/ c++构建->设置:工具设置选项卡-> GCC C编译器->包括

However, adding the include path to:

但是,添加包含路径到:

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

项目->属性-> C/ c++ General ->路径和符号->包括tab ->组装

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:

这是假设您不使用makefile。如果您这样做了,那么您可以忘记上面列出的更改。Eclipse将通过分析编译器日志自动找到所有需要的输入。我认为这很神奇,但它是这样运作的:

  • 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.
  • 更新索引:从项目窗口右键单击并选择“属性->索引->重建”。如果项目很大,您将在eclipse窗口右下角看到进度。

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.

我认为上面的过程可以用不同的方式来完成,eclipse也可以自己完成,但是对于我发现的手动处理的大型项目来说,上面所描述的操作不会让人分心。