Derek Lesho
Derek Lesho

Reputation: 338

Codeblocks can't find header files

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:

img

And this is what the project folder looks like:

img

What am I doing wrong?

Upvotes: 6

Views: 32651

Answers (3)

Peter
Peter

Reputation: 1

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.

Upvotes: 0

PiPatrol
PiPatrol

Reputation: 172

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

Upvotes: 11

neoaggelos
neoaggelos

Reputation: 640

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

Upvotes: 8

Related Questions