Author Topic: Does not recompile changed header files?  (Read 13756 times)

Offline Decrius

  • Multiple posting newcomer
  • *
  • Posts: 81
    • Daevius
Does not recompile changed header files?
« on: January 13, 2009, 08:23:41 pm »
Hey,

I am working on a library, I don't want to recompile everything every time...takes too much time.

Sometimes, if I only changed some code in the header file (typically template functions), it doesn't recompile it if I press Ctrl + F9. I _must_ press Ctrl + F11 to make it work. Is there a way CodeBlocks also recognises header file changes and recompiles them if needed?

Thanks.
Check out my website: http://www.daevius.com

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Does not recompile changed header files?
« Reply #1 on: January 14, 2009, 02:48:47 pm »
Works fine for me as long as the headers are added to the project. If they are not part of the project, they are not recompiled, because changes are not saved to disk when you hit "build". That, however, is intentional.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Decrius

  • Multiple posting newcomer
  • *
  • Posts: 81
    • Daevius
Re: Does not recompile changed header files?
« Reply #2 on: January 22, 2009, 04:50:49 pm »
Works fine for me as long as the headers are added to the project. If they are not part of the project, they are not recompiled, because changes are not saved to disk when you hit "build". That, however, is intentional.

I have them added to the project, but changes to the header files doesn't always make it recompile correctly.
Check out my website: http://www.daevius.com

Offline rhf

  • Multiple posting newcomer
  • *
  • Posts: 123
Re: Does not recompile changed header files?
« Reply #3 on: January 22, 2009, 07:33:11 pm »
Decrius,

I don't know if this is your case, but I had a similar problem; that is, a modification in a header file in the project did not cause a recompilation.
In my case I was setting my library path in Settings->Compiler and debugger->Global compiler settings->Search directories.
Everything seemed to work - the modified header file was saved as expected, but the program was not recompiled. I had to do a Rebuild (Ctrl-F11) to force a re-compilation.  (I believe this is a bug.) To solve this problem I moved my library path to the Project->Build options->Search directories.

Also, occasionally I would have problems when debugging, and this seemed to go away when I always use the absolute (as opposed to relative) path in the Project->Build options->Search directories.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5219
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does not recompile changed header files?
« Reply #4 on: January 23, 2009, 03:53:53 am »
Decrius,

I don't know if this is your case, but I had a similar problem; that is, a modification in a header file in the project did not cause a recompilation.

I don't have the problem( I just tested yet), make sure your header file was include in your project as thomas said.


Quote
Also, occasionally I would have problems when debugging, and this seemed to go away when I always use the absolute (as opposed to relative) path in the Project->Build options->Search directories.
What's your problem when debugging? Absolute path is recommended in compiling if you want to debug using GDB.

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 rhf

  • Multiple posting newcomer
  • *
  • Posts: 123
Re: Does not recompile changed header files?
« Reply #5 on: January 23, 2009, 05:25:50 pm »
What's your problem when debugging?
Program would not stop at a break in header.
Quote
Absolute path is recommended in compiling if you want to debug using GDB.
Thanks. I sort of figured that out. I did not realize it was recommended.

Offline rhf

  • Multiple posting newcomer
  • *
  • Posts: 123
Re: Does not recompile changed header files?
« Reply #6 on: January 23, 2009, 05:46:41 pm »
...make sure your header file was include in your project as thomas said.
Thanks, ollydbg, but that is exactly the situation I am describing. The header file is definitely in my project.

As I describe above, if the path to the header file is in my Project Search directories, when I modify the header file and then do a Build (Ctrl-F9), the modified header file is saved and the affected files are re-compiled as expected.

However, if the path to the header file is in my Global compiler settings Search directories, and not in the Project Search directories, then when I do a Build, the modified header file is saved, but the affected files are not re-compiled. I have to do a Rebuild (Ctrl-F11) to force the re-compilation, which of course re-compiles everything, not just the affected files.

This is on Windows XP with latest SVN  releases.

Offline Decrius

  • Multiple posting newcomer
  • *
  • Posts: 81
    • Daevius
Re: Does not recompile changed header files?
« Reply #7 on: February 03, 2009, 08:45:37 pm »
Thanks rhf, that was indeed the problem!

Adding the path to the projects search paths and not only to the global makes it recompile all depending files on that header file. Also works if the path is in both project as global search paths.

Definitely a bug.
Check out my website: http://www.daevius.com

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #8 on: June 20, 2012, 11:30:13 am »
Definitely a bug.
I hate to refloat a thread SO old, but I have recently come across this bug too, and I didn't find this mentioned any more recently. So, just take it as a reminder...

It's nasty to have files included in the project and not taken into account for changes ;)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11770
    • Travis build status
Re: Does not recompile changed header files?
« Reply #9 on: June 20, 2012, 11:48:42 am »
Please provide an example project and the steps needed to reproduce the problem.
I've never seen this bug and I use lots of headers not included in the project.
(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 carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #10 on: June 20, 2012, 12:18:05 pm »
I suspect this is happening when the header being included in the project is in another folder. I use a separate folder to keep all headers so they can be all by included by other projects from the same location.

I'll try to upload a simple example later.

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #11 on: June 20, 2012, 03:06:15 pm »
I have been investigating this and, ironically, what I have actually found (so far) is a case of the opposite! A project that keeps being rebuilt even when no files had been touched.

On every click on Rebuild I keep getting this message...

Quote
-------------- Build: Release in RebuildTest (compiler: GNU GCC Compiler)---------------

g++.exe -L. -LC:\Programacion\KTools\Libraries  -o .\RebuildTest.exe .\Main.o   -s -static-libgcc -static-libstdc++  
Output size is 7.50 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)

In other projects I have, it just shows the typical "Nothing to be done" message, but in this one it never happens...

What I have seen that happens here, is that the object file is never touched (last modification time keeps constant), but exe file keeps being relinked for some reason.

Attached is a simple project where I have this happening. Let's see if you can reproduce it

EDIT: I have found that this only happens when I turn on the "use flat objects" compiler option. Turning it off stops relinking and shows the "Nothing to be done" message.

[attachment deleted by admin]
« Last Edit: June 20, 2012, 04:28:17 pm by carra »

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #12 on: June 20, 2012, 04:27:09 pm »
Aargh! I needed WAY too much time to isolate the problem (I'm working with whole workspaces now), but I have finally attached a single project that does NOT recompile properly on header changes, even with "use flat objects" option turned off.

The project consists of 3 files:

- General.hpp
- LogStream.hpp
- LogStream.cpp

Any changes in the CPP file or LogStream.hpp trigger a recompile.
But changes General.hpp do not produce recompile, and instead the "Nothing to be done" message appears.

This has been tested on latest nighlty a.k.a. build 8059.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6535
    • My Best Post
Re: Does not recompile changed header files?
« Reply #13 on: June 20, 2012, 04:32:34 pm »
Aargh! I needed WAY too much time to isolate the problem (I'm working with whole workspaces now), but I have finally attached a single project that does NOT recompile properly on header changes, even with "use flat objects" option turned off.

The project consists of 3 files:

- General.hpp
- LogStream.hpp
- LogStream.cpp

Any changes in the CPP file or LogStream.hpp trigger a recompile.
But changes General.hpp do not produce recompile, and instead the "Nothing to be done" message appears.

This has been tested on latest nighlty a.k.a. build 8059.

Code: [Select]
C:\Users\stahta01\Downloads\KTools2\KTools2\Sources\LogStream\..\..\Headers\LogStream.hpp|10|fatal error: ..\..\Headers\General.hpp: No such file or directory|

FYI: To get it to compiler, I had to change global compiler setting.
Build options: "Explicitly add currently compiling file's location to search dirs." to be checked

NOTE: I then did NOT see the described problem. Tested with self compiled SVN 8060

Tim S.

PS:
The below is considered bad style
Code: [Select]
#include "..\..\Headers\General.hpp"

Preferred style is using "/" instead of "\"
Code: [Select]
#include "../../Headers/General.hpp"

 
« Last Edit: June 20, 2012, 04:42:27 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #14 on: June 20, 2012, 05:07:25 pm »
FYI: To get it to compiler, I had to change global compiler setting.
Build options: "Explicitly add currently compiling file's location to search dirs." to be checked

You are right on that, I always have "." as a search directory for the compiler. Still, I believe it should have worked. Including "header.h" (with quotes) is expected to be searched in the source file's directory, as stated here: http://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html

Anyway, this doesn't have to do with the recompile issue I mentioned. Let's see if someone else experiences it too
« Last Edit: June 20, 2012, 05:17:37 pm by carra »

Offline jarod42

  • Multiple posting newcomer
  • *
  • Posts: 82
Re: Does not recompile changed header files?
« Reply #15 on: June 20, 2012, 05:16:17 pm »
tested with release version 10.05
Adding -I. to compile successfully
and I reproduce the bug.

Watching the LogStream.depend:
strange: 3 entries for logstream.cpp (with different path)

Code: [Select]
1340202085 c:\programacion\ktools2\headers\logstream.hpp
<string>
<fstream>
<stdexcept>
"..\..\Headers\General.hpp"
And I don't know how depend handle relative path
since
..\..\Headers\General.hpp should be relative to logstream.cpp directory
and not from LogStream.hpp directory (and it is LogStream.hpp which depends directly on General.hpp).
« Last Edit: June 20, 2012, 05:19:05 pm by jarod42 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11770
    • Travis build status
Re: Does not recompile changed header files?
« Reply #16 on: June 20, 2012, 05:31:52 pm »
10.05 is highly uninteresting version to test this :)
(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 carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #17 on: June 20, 2012, 08:31:57 pm »
Well, yes: some recent version would be better. But at least, that makes it less likely that the issue is just some bad configuration on my part  :)

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Does not recompile changed header files?
« Reply #18 on: June 20, 2012, 11:30:20 pm »
It works correctly here on windows (7600) and linux (8059).

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #19 on: June 20, 2012, 11:50:56 pm »
It works correctly here on windows (7600) and linux (8059).
Interesting, I have just tried the example on another computer (this one is windows, C::B 7966) and exactly the same happens. I can modify General.hpp as I want, even with illegal syntax, and it never recompiles.

But the fact that both you and I get consistent results on our different systems is interesting. Maybe it has something to do with the  C::B configuration we use??

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6535
    • My Best Post
Re: Does not recompile changed header files?
« Reply #20 on: June 21, 2012, 12:05:38 am »
@carra:

Do you try doing a full re-build before just changing something in the header file?
In other words these steps
1. Do a full re-build
2. Do a build and verify nothing is done.
3. Edit the header file
4. Do a build and see if it builds

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

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5219
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does not recompile changed header files?
« Reply #21 on: June 21, 2012, 03:37:32 am »
I download the KTool2.zip, and tested it.
First, I change
Code: [Select]
"..\..\Headers\General.hpp"

Code: [Select]
"General.hpp"

Then I build OK.

Next, I change any header file, then click build button.

I can't reproduce your issue, every thing works fine. (the cpp file will be re-compiled if a header file changes)
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 jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Does not recompile changed header files?
« Reply #22 on: June 21, 2012, 06:14:03 am »
I download the KTool2.zip, and tested it.
First, I change
Code: [Select]
"..\..\Headers\General.hpp"

Code: [Select]
"General.hpp"

Then I build OK.

Next, I change any header file, then click build button.

I can't reproduce your issue, every thing works fine. (the cpp file will be re-compiled if a header file changes)
i had to change it touse "/" instead of "\" on linux, and added "." to the compiler search-directories as carra did.

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #23 on: June 21, 2012, 09:48:17 am »
Done this, results are down there on red
Do you try doing a full re-build before just changing something in the header file?
In other words these steps
1. Do a full re-build --> Done, everything rebuilds as usual
2. Do a build and verify nothing is done. --> Nothing to be done message
3. Edit the header file --> file modified
4. Do a build and see if it builds --> Again, nothing to be done message

Question: For those of you who cannot reproduce the bug, what is your *.depend file showing?? Because mine is this:

Code: [Select]
# depslib dependency file v1.0
1340202051 source:c:\programacion\ktools2\sources\logstream\logstream.cpp
"..\..\Headers\LogStream.hpp"
<time.h>
<iostream>

1340202085 c:\programacion\ktools2\headers\logstream.hpp
<string>
<fstream>
<stdexcept>
"..\..\Headers\General.hpp"

As you can see, this is consistent with the problem (there is no entry for General.hpp)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5219
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does not recompile changed header files?
« Reply #24 on: June 21, 2012, 09:57:01 am »
It is mine
Code: [Select]
# depslib dependency file v1.0
1340201559 source:c:\programacion\ktools\sources\logstream\logstream.cpp
<LogStream.hpp>
<time.h>
<iostream>

1339684374 source:c:\programacion\librerias\ktools\sources\logstream\logstream.cpp
<LogStream.hpp>
<time.h>
<iostream>

1340202051 source:c:\programacion\ktools2\sources\logstream\logstream.cpp
"..\..\Headers\LogStream.hpp"
<time.h>
<iostream>

1340202085 c:\programacion\ktools2\headers\logstream.hpp
<string>
<fstream>
<stdexcept>
"..\..\Headers\General.hpp"

1340202051 source:e:\code\cb\test_code\ktools2\sources\logstream\logstream.cpp
"..\..\Headers\LogStream.hpp"
<time.h>
<iostream>

1340242660 e:\code\cb\test_code\ktools2\headers\logstream.hpp
<string>
<fstream>
<stdexcept>
"General.hpp"

1340242644 e:\code\cb\test_code\ktools2\headers\general.hpp

Note: I have change your sample file a little to avoid a build error.
I download the KTool2.zip, and tested it.
First, I change
Code: [Select]
"..\..\Headers\General.hpp"

Code: [Select]
"General.hpp"

Then I build OK.

Next, I change any header file, then click build button.

I can't reproduce your issue, every thing works fine. (the cpp file will be re-compiled if a header file changes)
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 jarod42

  • Multiple posting newcomer
  • *
  • Posts: 82
Re: Does not recompile changed header files?
« Reply #25 on: June 21, 2012, 10:26:39 am »
If I put '.' in search directory. It works as expected.
else if I add '-I.' as build option, I get the "Nothing to be done message".

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #26 on: June 21, 2012, 10:44:04 am »
As expected, you are not having the bug because your depend file has an entry for General.hpp. So why does my C::B not create the entry and yours does? Jarod's last comment is interesting, and it may shed some light on this. But maybe some people here have knowledge on how depend files are generated.

Also, some of you may be suspecting of the line
#include "..\..\General.hpp"
but I can confirm this is not the cause: The sample project I uploaded is just an "adapted copy", but the real project I'm writing (which has the same bug) uses absolute paths, and its include line is a more standard #include <General.hpp>

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11770
    • Travis build status
Re: Does not recompile changed header files?
« Reply #27 on: June 21, 2012, 10:58:58 am »
Do you have General.hpp in the filesystem or general.hpp?
Try matching the case.
On windows the case doesn't matter for files, but the dependency generator can be broken if the cases doesn't match.
(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 carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #28 on: June 21, 2012, 11:47:23 am »
Yes, cases do match in all file and folder names.

But I did find something new: I tried removing "General.hpp" from the project and my depend file changed to this:

Code: [Select]
# depslib dependency file v1.0
1340201559 source:c:\programacion\ktools\sources\logstream\logstream.cpp
<LogStream.hpp>
<time.h>
<iostream>

1339684374 source:c:\programacion\librerias\ktools\sources\logstream\logstream.cpp
<LogStream.hpp>
<time.h>
<iostream>

This time, LogStream.hpp is the one missing!! And even if I readd to the project, it keeps missing, so now the 2 headers are missing from *.depend.

This makes me think that the bug we have is one (or both) of the following:

(1) C::B fails to update depend file when some relevant project changes happen
(2) C::B is somehow failing to include the first file in the project. The first file, before changing (as shown below), was General.hpp. After removing it, the first file is LogStream.hpp.

      <Unit filename="..\..\Headers\General.hpp" />
      <Unit filename="..\..\Headers\LogStream.hpp" />
      <Unit filename="LogStream.cpp" />

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #29 on: June 21, 2012, 02:34:12 pm »
Some more info: it seems that the missing entries in depend file are not the cause of the problem but an effect. I replaced the depend file with an earlier version (which had all files included) and C::B is ignoring it: no rebuild when changing any of the headers.

... and I don't think there is much more I can do. I tried most things I can think of... I think this will need an analysis of the source code.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Does not recompile changed header files?
« Reply #30 on: June 21, 2012, 02:45:19 pm »
Some more info: it seems that the missing entries in depend file are not the cause of the problem but an effect. I replaced the depend file with an earlier version (which had all files included) and C::B is ignoring it: no rebuild when changing any of the headers.

... and I don't think there is much more I can do. I tried most things I can think of... I think this will need an analysis of the source code.

there is something, you totally ignore in your posts.
It works on some (many ?, most ?) systems, windows and linux.
So it still might be an issue on your system(s).

Can you please check the timestamps of the source-, header- and object-files, before and after a normal build and a full rebuild ?

Offline carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #31 on: June 21, 2012, 03:14:44 pm »
I've checked it, here are the results:

Code: [Select]
FILE BEFORE BUILD AFTER BUILD AFTER REBUILD
General.hpp 15:02:28 15:02:28 15:02:28
LogStream.hpp 15:02:26 15:02:26 15:02:26
LogStream.cpp 14:25:17 14:25:17 14:25:17
LogStream.o 15:02:07 15:02:07 15:08:16
libLogStream.a 15:02:07 15:02:07 15:08:16

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5219
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does not recompile changed header files?
« Reply #32 on: June 21, 2012, 03:24:59 pm »
I think this will need an analysis of the source code.

Mostly I think the source code is in depslib. :)
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 carra

  • Multiple posting newcomer
  • *
  • Posts: 114
Re: Does not recompile changed header files?
« Reply #33 on: June 21, 2012, 05:39:58 pm »
Solved: I found details in this thread: http://forums.codeblocks.org/index.php?topic=10803.0.

It seems that the options set in the global "Compiler settings" are not going through the depslib processing. Only the ones in "Project build option" are. So, the GCC command line is sent the options information but depslib isn't. Therefore, depslib could not find the dependency files. And that is also why the sample project worked for you: it was using quoted include, and you were using project settings (not compiler settings).

Unfortunately, from a user perspective that is not intuitive. Is this a conscious decision? I always use the same include & library folder, and it would be way more convenient (an maintainable) to just set it once instead of setting it on every project...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11770
    • Travis build status
Re: Does not recompile changed header files?
« Reply #34 on: June 21, 2012, 05:57:13 pm »
Unfortunately, from a user perspective that is not intuitive. Is this a conscious decision? I always use the same include & library folder, and it would be way more convenient (an maintainable) to just set it once instead of setting it on every project...
Yes, but this is considered a bad practice to put something in there.
And I guess this is an optimization for the dependency checking.
As the include/lib search paths are meant for setting paths to SDK which doesn't change often.
C::B has lots of tools to make it easy for the user to setup projects the right way. You can even script it.
(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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5219
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does not recompile changed header files?
« Reply #35 on: June 24, 2012, 08:32:23 am »
There is some thing off topic, can we use the gcc option "-MF" to generate a dependency file.
Then we can use the dependency file to check whether we need to build some cpp files.
see:
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Preprocessor-Options.html
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.