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

发布于 2024-12-20 17:39:14 字数 466 浏览 6 评论 0原文

我正在尝试将文件导入 Eclipse C 项目并编译它。构建过程找不到本地头文件。头文件位于 src 目录中。如何在 Eclipse 中编辑包含路径?如果我手动执行此操作,我可以在 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

韵柒 2024-12-27 17:39:14
  1. 右键单击该项目并选择属性。
  2. 选择C/C++常规->路径和符号。
  3. 选择“包括”选项卡。
  4. 在语言列表中,选择“GNU C”或您使用的任何 C 编译器工具链。
  5. 按“添加...”按钮并添加包含文件的目录。
  6. 关闭属性窗口并重建。您应该会看到新路径在构建过程中被用作 -I
  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.
饮惑 2024-12-27 17:39:14

到目前为止,我发现的所有内容都没有帮助,除其他外,在以下位置添加包含路径对我来说不起作用

  • 项目->属性-> C/C++ 通用 ->路径和符号 ->包括选项卡 -> GCC C
  • 项目 ->属性-> C/C++ 通用 ->路径和符号 ->包括选项卡 -> GCC C++
  • 项目 ->属性-> C/C++构建->设置:工具设置选项卡-> GCC C++ 编译器 ->包括
  • 项目->属性-> C/C++构建->设置:工具设置选项卡-> GCC C 编译器 -> 但是,将

包含路径添加到:

项目->属性-> C/C++ 通用 ->路径和符号 ->包括
选项卡->装配

在检查“添加到所有语言”时进行

确实有效。奇怪的是,最后一个选项完成了上述所有操作 - 为什么它们不能单独工作,我不太清楚。

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

  • 从项目菜单构建全部 - 即使成功,它也可能会因为未知符号等而使某些文件标记为“错误”,因此您必须执行第二步:
  • 更新索引:在项目窗口中右键单击并选择“属性 -> 索引 -> 重建”。如果项目很大,您将在 Eclipse 窗口的右下角看到进度。

我认为上述过程可以通过不同的方式完成eclipse 可以自己完成这一切也是如此,但对于大型项目,我发现如上所述的手动处理不太分散注意力。

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.

枫以 2024-12-27 17:39:14

Alt + Enter 用于打开属性。

打开C/C++ 常规 ->路径和符号 ->包括->添加...

请注意,有时您需要选择“是工作空间路径”(例如:对于链接的文件夹)。

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

泅渡 2024-12-27 17:39:14

1.单击源文件夹

2.选择“新建”

3.接下来选择“头文件”

4.给出带有“.h”扩展名的正确名称(例如:header.h)

5.然后选择“完成”

6.然后创建您的函数

7.保存您的“header.h”文件

8.然后从控制台顶部选择“项目”

9.选择“构建全部”

10.然后打开您的“.c”文件

11.写入 #include"header(参见步骤 4).h" 以使用头文件

12.按照步骤 7 至 9

13.然后单击控制台顶部的“运行”

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文