Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeblocks can't find header files

Tags:

c++

codeblocks

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?

like image 287
Derek Lesho Avatar asked Sep 20 '15 18:09

Derek Lesho


2 Answers

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

like image 113
PiPatrol Avatar answered Sep 29 '22 20:09

PiPatrol


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

like image 43
neoaggelos Avatar answered Sep 29 '22 20:09

neoaggelos