Author Topic: Header dependency in the build  (Read 6528 times)

Offline mdzahidh

  • Single posting newcomer
  • *
  • Posts: 6
Header dependency in the build
« on: December 29, 2009, 01:08:27 pm »
I ported the PBRT (Physically Based Rendering Toolkit) source code into Codeblocks project (not using the custom makefile provided by the PBRT). The the trouble is, the header dependency is not working properly. For example if a cpp file A.cpp includes A_header.h and if i modify A_header.h, and do a build, the A.cpp is not recompiled and the the build system does nothing ! However, if i right click on the line of A.cpp
where it says "include A_header.h" and say "Open header" it opens A_header.h properly. So obviously the system can locate the header file but for some reason, the dependecy of A.cpp on A_header.h is not workign properly at build time.

zabzonk

  • Guest
Re: Header dependency in the build
« Reply #1 on: December 29, 2009, 01:12:23 pm »
Are you sure the modification times on the sources are consistent with the system time on your own box?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Header dependency in the build
« Reply #2 on: December 29, 2009, 01:16:03 pm »
works fine here, which version of CB did you use?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline mdzahidh

  • Single posting newcomer
  • *
  • Posts: 6
Re: Header dependency in the build
« Reply #3 on: December 29, 2009, 10:18:03 pm »
yes, i checked the modification time and it is consistent with the system time. I modified the file from within CB and checked the modification time using "stat" Even if a header file is modified the corresponding source wouldn't be recompiled when I do a build !

I am using CB 8.02. Any idea why isn't this working ? :(

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Header dependency in the build
« Reply #4 on: December 29, 2009, 10:42:05 pm »
Simple Questions that I have no idea if the apply to Code::Blocks IDE.

1. Are you using include "file.h" or <file.h>?
I would guess include "file.h" is correct.

2. Does the header file belong to the project?
I would add the header to the project.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline mdzahidh

  • Single posting newcomer
  • *
  • Posts: 6
Re: Header dependency in the build
« Reply #5 on: December 29, 2009, 10:52:20 pm »
Yes, both conditions are satisfied ! The situation is, the source tree has several directories.. so for example it has a directory called "volumes", see below

src
 |
 |----> volumes
              |
              |exponential.h
              |exponential.cpp

So both exponential.h and exponential.cpp are in the same folder "volumes." In the file "exponential.cpp" its written

#include "volumes/exponential.h"  // since the build is performed from the root directory "src"

but if i change/modify exponential.h then and then do a "build", it says "Nothing to be done" :(


zabzonk

  • Guest
Re: Header dependency in the build
« Reply #6 on: December 29, 2009, 10:54:49 pm »
Quote
yes, i checked the modification time and it is consistent with the system time. I modified the file from within CB and checked the modification time using "stat"

But are the times for the .cpp files that depend on the header consistent? In other words, are their times prior to that on the modified header?

Offline mdzahidh

  • Single posting newcomer
  • *
  • Posts: 6
Re: Header dependency in the build
« Reply #7 on: December 29, 2009, 10:55:43 pm »
Arright, i think i found a pattern here.

if in a .cpp file the headers are included without directory prefix for example

#include "someheader.h"

then modifying that header also triggers a recompilation of the source file :)

but if its written

#include "dir/someheader.h"

it fails to recognize the modifications in the header file :(

zabzonk

  • Guest
Re: Header dependency in the build
« Reply #8 on: December 29, 2009, 11:41:44 pm »
As stahta01 asked - are you adding these header files to the project? The mere fact that a header exists somewhere on the system, even if it is on the include path does, not guarantee the dependency mechanism will do what you want.

Offline mdzahidh

  • Single posting newcomer
  • *
  • Posts: 6
Re: Header dependency in the build
« Reply #9 on: December 29, 2009, 11:44:10 pm »
yes, the headers are added in the project as well ! but i dont know if it is CB feature or not, the header files (in the project browser) is colored gray. Does that imply anything ?

zabzonk

  • Guest
Re: Header dependency in the build
« Reply #10 on: December 29, 2009, 11:53:01 pm »
Quote
Does that imply anything?

I have no idea :-)  But that's how they appear in my projects, and I have no dependency problems.

Offline mdzahidh

  • Single posting newcomer
  • *
  • Posts: 6
Re: Header dependency in the build
« Reply #11 on: December 29, 2009, 11:58:02 pm »
but im kinda convinced that it has something to do with the directory prefix in header , the one that i talked about earlier. And I noticed that this pattern is consistent throughout the project, where ever i have directory prefix in my while including the header, the header dependency gets screwed. Could be a bug in CB ?