Eclipse C/C++ (CDT) 将文件导入项目 - 未找到头文件 - 包含路径
我正在尝试将文件导入 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
-I
。-I
in build process.到目前为止,我发现的所有内容都没有帮助,除其他外,在以下位置添加包含路径对我来说不起作用:
包含路径添加到:
在检查“添加到所有语言”时进行
确实有效。奇怪的是,最后一个选项完成了上述所有操作 - 为什么它们不能单独工作,我不太清楚。
这是假设您不使用 makefile。如果这样做,您就可以忘记上面列出的更改。 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:
However, adding the include path to:
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:
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.
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).
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