代码块找不到头文件 [英] Codeblocks can't find header files

查看:111
本文介绍了代码块找不到头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:


严重错误:imports.h:没有这样的文件或目录

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

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

This is my project hierarchy in codeblocks:

这是项目文件夹的样子:

And this is what the project folder looks like:

我在做什么错了?

推荐答案

我知道这是几年后的事,但是最近,我看到学生们按照我的看法坦率地说是不好的建议,例如上面给出的建议。对于那些学习c ++的人,此功能不适合您。要添加标题,您只需检查您使用的是双引号,而不是尖括号,即

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.

#include "myheader.h"

而不是

#include <myheader.h>

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

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

这篇关于代码块找不到头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆