Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: kfmfe04 on July 06, 2009, 09:14:03 pm

Title: Dependencies on .hpp files not triggering [SOLVED]
Post by: kfmfe04 on July 06, 2009, 09:14:03 pm
I have a static lib project with a bunch of .cpp files and .hpp files.

When I modify a .cpp file and build, the proper files get compiled and linked.
When I modify a .hpp file and build, I get:

Target is up to date.
Nothing is to be done.

I have tried it on .hpp files #include'd in a .cpp file and ones that are not.
All .hpp files are set to "Belong in targets: Debug and Release."

I don't know what I should do to ensure that a rebuild depends on changes in the .hpp files.  At least, it should rebuild on changes to MyClass.hpp if MyClass.cpp #include's it...

Any ideas where I should check for dependencies?
Thanks in advance.

Title: Re: Dependencies on .hpp files not triggering
Post by: kfmfe04 on July 06, 2009, 09:47:12 pm
Update: I right-click on MyClass.hpp and select Properties > Build > Compile file, which causes gcc to build a .gch file.

Now, if I modify a header file in my static library (unpleasant result):
1.  it causes the static library to build (GOOD)
2.  but my second project (executable) which depends on that static library does not link (BAD)

In contrast, if I modify a cpp file in my static library (good result):
1.  it causes the static library to build (GOOD)
2.  my executable project relinks (GOOD)

At this point, I am indifferent towards using .gch files or not - but I need the system to build and link the right files when I change a header file in the library, or development becomes quite difficult.

Any ideas what settings may be off?
Title: Re: Dependencies on .hpp files not triggering
Post by: Jenna on July 06, 2009, 10:38:58 pm
Are the dependencies set correctly ?

Dependencies have to be set in projects "Properties  -> Build targets -> External dependencies -> External dependency files" , to make sure the executable is rebuild and or relinked, if the library changes
and in  "Properties  -> Project settings -> Project's dependencies", to make sure the library is updated (if necessary) before the executable gets build/linked.
Title: Re: Dependencies on .hpp files not triggering
Post by: kfmfe04 on July 07, 2009, 06:23:09 am
Hi Jens,

Thank you for your suggestions.  

I tried both your suggestions, but it isn't working yet.  Those settings seem to affect relinks, but not recompiles.

I will be more specific.  

MyStaticLib:  libheader.hpp (no .cpp - implementation in header), other.cpp, other.hpp ...
MyApp:  app.cpp (#include's libheader.hpp) ...

---------------------------------------------------------------------------------
What I need is for app.cpp to depend on libheader.hpp so that it recompiles app.o when libheader.hpp changes.
---------------------------------------------------------------------------------

The two suggestions you had affect relinks, but not a recompile to app.o ...

If this is a limitation of C::B, I can probably script around this, but I am hoping, instead, that I am doing something wrong...

Regards,
Ken

(BTW, since it is a library, I should implement in .cpp instead, but there are special cases, like inline, that have to be in .hpp so it would be nice to get the dependencies right during development...)


Title: Re: Dependencies on .hpp files not triggering
Post by: MortenMacFly on July 07, 2009, 06:46:01 am
MyStaticLib:  libheader.hpp (no .cpp - implementation in header), other.cpp, other.hpp ...
MyApp:  app.cpp (#include's libheader.hpp) ...
If app.cpp includes header.hpp of the "lib" than this works very well for me... (even if header.cpp does not have a cpp file)?!
Title: Re: Dependencies on .hpp files not triggering
Post by: stahta01 on July 07, 2009, 06:52:31 am
MyStaticLib:  libheader.hpp (no .cpp - implementation in header), other.cpp, other.hpp ...
MyApp:  app.cpp (#include's libheader.hpp) ...
If app.cpp includes header.hpp of the "lib" than this works very well for me... (even if header.cpp does not have a cpp file)?!

IIRC, it makes a difference whether double quotes or square brackets are used.

I think the below should work.
Quote
#include "header.hpp"

The below may not work.
Quote
#include <header.hpp>

 Tim S.
Title: Re: Dependencies on .hpp files not triggering
Post by: kfmfe04 on July 07, 2009, 07:39:15 am
Hi Tim,

Your comment was very helpful.  I am still having problems, but I'm getting closer to resolving it.  I tried 2 things:

A -----------------------------
1. #include "libheader.hpp" in app.cpp
2. rebuild - OK, because I touched app.cpp
3. modify and save libheader.hpp
4. rebuild - BAD: doesn't recompile app.cpp

B -----------------------------
1. #include "my_full_path_to_header/libheader.hpp" in app.cpp
2. rebuild - OK, because I touched app.cpp
3. modify and save libheader.hpp
4. rebuild - OK!!!  Rebuilds app.cpp

I noticed the file app.depend with a comment line # depslib dependency file v1.0

So I am wondering now, if somehow my -Imy_full_path_to_header is being passed to g++ (validated in app_build_log.html), but not being passed to depslib? 

Is depslib part of C::B or a 3rd party lib?

- Ken

Quote

IIRC, it makes a difference whether double quotes or square brackets are used.

I think the below should work.
Quote
#include "header.hpp"

The below may not work.
Quote
#include <header.hpp>

 Tim S.

Title: Re: Dependencies on .hpp files not triggering
Post by: kfmfe04 on July 07, 2009, 07:51:19 am
With the help of your comments, I figured out the problem.

There are several places to put search directories for the compiler.
I know of:

1. Compiler and debugger settings > Global compiler settings > Search directories > Compiler
2. Project > Build Options > Search directories

---------------------------------------------------------------------
I had made the mistake of putting my library search directory in 1.
Once I removed it from 1. and put it into 2., compiles were fine.
---------------------------------------------------------------------

Doing 1. or 2. don't seem to impact the compiler, per se (maybe ordering?), but it definitely impacts depslib.  Come to think of it, the design of the dependency system makes perfect sense, but it's easy to fall into this kind of gotcha when trying a new IDE.

Thanks everyone for commenting - it helps a lot to get a sanity check/idea bounces from everyone.  I really appreciate it.

Regards,
Ken
(One sidenote - it doesn't seem to make a difference if I use #include <> or #include "" - in the old C-days, #include "" used to mean don't use the -Ipaths to look for headers, but this doesn't seem to apply any more...  ...I can't seem to find a difference between the two for C++)