C++ 代码块找不到头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32682860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:11:35  来源:igfitidea点击:

Codeblocks can't find header files

c++codeblocks

提问by Derek Lesho

So a few hours ago I started learning c++ in codelite but I was getting frustated with, so I just got codeblocks and imported the project. But now whenever I try to compile it returns:

所以几个小时前我开始在 codelite 中学习 c++,但我很沮丧,所以我只得到了代码块并导入了项目。但是现在每当我尝试编译它时都会返回:

fatal error: imports.h: No such file or directory

致命错误:imports.h:没有那个文件或目录

This is my project hierarchy in codeblocks:

这是我在代码块中的项目层次结构:

img

图片

And this is what the project folder looks like:

这就是项目文件夹的样子:

img

图片

What am I doing wrong?

我究竟做错了什么?

回答by PiPatrol

I know this is years later, but I've recently seen students following what I deem is frankly bad advice such as what is given above. For those learning c++ this functionality is NOT for you. To add headers you should simply check that you are using double quotes, instead of angled brackets i.e.

我知道这是多年以后,但我最近看到学生遵循我认为坦率地说是糟糕的建议,例如上面给出的建议。对于那些学习 C++ 的人来说,这个功能不适合你。要添加标题,您应该简单地检查您使用的是双引号,而不是尖括号,即

#include "myheader.h"

and NOT

并不是

#include <myheader.h>

Angled brackets are meant for libraries (informally) and adding a simple header file for you basic classes does not require you to change default search directories. The problem comes when someone else tries to run your code (assuming you're doing this for uni) and their IDE isn't setup to search for a "library" (your header) where it shouldn't be. Double quotes tells the compiler the files exist in your current relative directory. This way you can keep your main, headers and header implementation in one directory. Fiddling with your IDE should only be done when necessary. KISS

尖括号用于库(非正式地),为您的基本类添加一个简单的头文件不需要您更改默认搜索目录。当其他人尝试运行您的代码(假设您是为 uni 执行此操作)并且他们的 IDE 未设置为搜索不应该出现的“库”(您的标题)时,问题就会出现。双引号告诉编译器文件存在于您当前的相对目录中。通过这种方式,您可以将 main、headers 和 header 实现保存在一个目录中。摆弄您的 IDE 应该只在必要时进行。吻

回答by neoaggelos

You have to tell Codeblocks where to find the header files that you include. Try adding the full path to your '/Headers' in the include directories of codeblocks

您必须告诉 Codeblocks 在哪里可以找到您包含的头文件。尝试在代码块的包含目录中添加“/Headers”的完整路径

Goto 'Codeblocks menu > Settings > Compiler > Search directories > Add'.

转到“代码块菜单 > 设置 > 编译器 > 搜索目录 > 添加”。

EDIT: Since your issue, however, is quite irrelevant to learning the C++ language itself, I suggest that you start with simpler programs, then move on to more complex ones. That, of course, unless you have previous experience with other programming languages

编辑:然而,由于您的问题与学习 C++ 语言本身无关,我建议您从更简单的程序开始,然后转向更复杂的程序。当然,除非您以前有使用其他编程语言的经验

回答by Peter

Since I haven't found any Makro for

因为我还没有找到任何 Makro

#define 'hostname of device where compiler is located' // which is unique and not to be copied !

I have now successfully used and included

我现在已经成功使用并包含

#include "myCompileEnv.h" 

as a workaround with the comments above, which is located more central - above the project directories in CodeBlocks.

作为上述注释的解决方法,它位于更中心 - CodeBlocks 中的项目目录上方。