Codeblocks can't find header files

[亡魂溺海] 提交于 2019-12-18 03:44:10

问题


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:

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:

What am I doing wrong?


回答1:


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"

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




回答2:


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

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




回答3:


Since I haven't found any Makro for

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



来源:https://stackoverflow.com/questions/32682860/codeblocks-cant-find-header-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!