Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: Gerd on May 09, 2013, 04:03:23 am
-
When adding a class to a cpp project I get a headerfile in my include folder and the cpp file in the scr folder, but #include "headername.h" which is automatically included in the cpp file, is not found.
This can be avoided by using #include "../include/headername.h" but I wounder why this is.
Why does codeblocks by default add a include line that does not work (neither in windows nor linux)
People keep telling me it's a Bug but I would like to get an answer from those who know for sure.
Thank you for any help
-
People keep telling me it's a Bug but I would like to get an answer from those who know for sure.
I'm not sure if it is a bug.
But just add "include" in your Project->Build options->Search dirs -> Compiler and it will work.
-
I think it would be usefule to make it configurable to explicitely add the include path to the current projects include paths.
But where to place it ?
In the classwizard-dialog or as question after creating it, just like the add to current project question ?
As we have the dialog, that asks whether the newly created class-files should be added to the current project or not, it would make more sense to have an extra dialog for it, but it would be another extra click.
By the way wouldn't it make sense to make it possible to add the class (and the includes) on target-level and not onnly on project-level like it is done now ?
-
It's not a bug. 'gcc' looks for the include'd file in the folder of the file including it by default so it cannot find the 'include' folder obviously. Using '-iquote' includes the corresponding path to the search directories for quote style includes like "someheader.h". So add the following to your 'project-> build options-> compiler settings-> other options'.
-
Thank you for the comment.
I'm just wondering why this is a default behaviour.
Wouldn't it make sense to add -iquote $(PROJECT_DIR) by default?
-
Thank you for the comment.
I'm just wondering why this is a default behaviour.
Wouldn't it make sense to add -iquote $(PROJECT_DIR) by default?
I don't thinks so.
We have a similar setting: "Settings -> Compiler -> [your compiler] -> Build options -> Explicitely add project's toplevel directory to compiler search dirs".
But this does not find headers in subfolders like "include", neither does "-iquote $(PROJECT_DIR)".
-
But this does not find headers in subfolders like "include", neither does "-iquote $(PROJECT_DIR)".
I'm not sure what you meant here but what I meant was, if one uses 'iquote' with his/her main project directory and have the header file in 'project_dir/include' and source file in 'project_dir/src' then (s)he can include the header file in source file like "include/header.h" instead of "../include/header.h".
-
I think this should work by default, because the current working dir for running the compiler is the $(PROJECT_DIR).
I've never added that option and includes relative to the root of the project work as expected.
-
Then you must have some setting different cuz it doesn't work here. I do really want to know how you manage that as I don't want to use that option too.
Just to be sure, what you are saying is, you have include files in 'root/include' and sources in 'root/src' and you include with plain simple '#include "include/someheader.h"' and everything works as expected?
-
I think yes...