Author Topic: Does not recompile changed header files?  (Read 14221 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: 5226
  • 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: 12020
    • 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: 6644
    • 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 »