Author Topic: Path of headerfile  (Read 7407 times)

Offline Gerd

  • Single posting newcomer
  • *
  • Posts: 2
Path of headerfile
« 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

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Path of headerfile
« Reply #1 on: May 09, 2013, 07:53:50 am »
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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Path of headerfile
« Reply #2 on: May 09, 2013, 09:18:31 am »
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 ?
« Last Edit: May 09, 2013, 09:46:07 am by jens »

Offline scarphin

  • Lives here!
  • ****
  • Posts: 640
Re: Path of headerfile
« Reply #3 on: May 09, 2013, 09:52:16 am »
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'.
Code
-iquote $(PROJECT_DIR)

Offline Gerd

  • Single posting newcomer
  • *
  • Posts: 2
Re: Path of headerfile
« Reply #4 on: May 09, 2013, 01:24:38 pm »
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?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Path of headerfile
« Reply #5 on: May 09, 2013, 01:52:05 pm »
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)".

Offline scarphin

  • Lives here!
  • ****
  • Posts: 640
Re: Path of headerfile
« Reply #6 on: May 09, 2013, 04:08:36 pm »
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".

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Path of headerfile
« Reply #7 on: May 09, 2013, 04:13:22 pm »
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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 640
Re: Path of headerfile
« Reply #8 on: May 09, 2013, 10:10:40 pm »
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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Path of headerfile
« Reply #9 on: May 09, 2013, 11:22:50 pm »
I think yes...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]