So here is a problem I have observed for a while, and several users have reported that to me: the problem is that for some reasons and only for some projects, when I do a ‘build’ in Eclipse CDT, it does a ‘full’ build. It does not only build the changed files, it builds all or many files in the project.
I expect that only the changed files will be rebuild. Instead, it compiles many files it should not compile/build, with the result that a build takes a very long time. That’s clearly wrong, and not what I expect. So what is causing this problem?
The issue is present in multiple Eclipse version (Kepler, Luna), with different Eclipse distributions (Kinetis Design Studio v2.0.0 and v3.0.0) with different make utilities. In all my projects I’m using the GNU ARM Eclipse plugins, but I doubt that this is the problem. I believe it might be more of a CDT problem instead.
The first observation was: The issue seems not to happen for ‘fresh’ projects, but happens for ‘older’ projects or some projects I have received from other users. It is even more strange, that the number of files unnecessary recompiled seems to be kind of random: sometimes it just triggers a new linking phase, sometimes it seems to affect only one or a few files, sometimes it seems to rebuild pretty much all of them. And things might even change depending on which files I change.
File Dates?
First I thought there might be something wrong with the file dates, as make needs to rebuild something when a source file is newer than the object file, or if the header file is newer than the source file using it. I had once a machine where the host clock was going wild, resulting in strange file time stamps. But on my current machine everything was OK.
Debugging Make Files?
If the files are not newer, maybe some do not exist? Checking them on the file system, object files all where there, all with newer file dates than the source files. So I started to see what kind of debug information I can get from make. Make has a –debug option (see https://www.gnu.org/software/make/manual/html_node/Options-Summary.html) which is very useful for debugging make files.
The only thing I found was that somehow some object files do not exist:
Reading makefiles... Updating goal targets.... File 'all' does not exist. File 'FRDM-K64F_Demo.elf' does not exist. File 'Sources/Joystick.o' does not exist. Must remake target 'Sources/Joystick.o'. Building file: ../Sources/Joystick.c
But they *do* exist before running the build! Strange. So something is deleting them, and somehow it must be the build process? But I have not seen any ‘rm’ or ‘del’ in the make logs.
Build Automatically?
Then, I thought it might be related to ‘Build Automatically’ setting:
‘Build automatically’ actually does not make any difference, as this functionality seems not be implemented in CDT: that would allow that the system would automatically build my application after I have changed and saved my file. So this was a Red Herring :-(.
External or Internal Builder?
What I noticed was that using the Eclipse Internal Builder does not have this problem. The problem only happened with using the external builder (external make):
With the internal builder, Eclipse uses its own built-in make utility, while with the external builder the build process uses an external make. So I thought that I have found a problem in make: Using different make executables did not make any difference :-(.
Refresh Policy!
Actually, that ‘external builder’ was triggering something. After poking around this issue for a few days, finally I received a tip from Rock Li (thanks!): The issue seems to be related to the Refresh Policy setting in the project, which only affects external builders: If the refresh is set for an non-existing (or wrong directory), other than the project root directory itself, these strange rebuilds of files are happening:
And to my surprise: Deleting that wrong directory and using the project folder instead fixed the issue!
So the question is: what is this ‘Refresh Policy’ used for? As indicated in the dialog itself, it is only used if using an external builder (which is the case for my project). That refresh is executed after the build process, to make sure the Eclipse project knows about all the new files (object files, make files, etc) generated. But if that setting is wrong, wrong things might happen :-(.
And now I realize why I had some strange things with some projects, and not with others. That above project I had probably created as FRDM_K64F_Test, and then later renamed to FRDM_K64F_Demo, but that Refresh Policy setting did not get updated.
Summary
If your external make build in Eclipse CDT is taking too long and building too many files, then check what is specified in the Project settings, under Refresh Policy. If you have a wrong folder listed there, then this is very likely causing that problem.
I’m not sure if this is a problem of CDT, make or anything else. I just notice if I set the folder to the correct one, the issue goes away :-). If anyone has an explanation of what is happening, please comment :-).
Happy Building 🙂
I’ve noticed on Eclipse 3.8 that sometimes cross project references are not refreshing properly. This is a bug. Just manually Refreshing the project and also the associated projects seems to fix this issue.
Probably your issue is related to this problem.
I’ve also found that library projrcts don’t automatically have their directory links updated when the project name is changed. Sometimes I have to dive into the XML configs to delete dead references. Another bug.
But still prefer to use Eclipse 100x more than any proprietary Windows based platform.
LikeLike
Yes, it could be related to the same issue. But I’m still not clear why with the wrong refresh the make utility somehow has the object files deleted in my case. Really strange.
LikeLike
Thanks Erich,
I got a problem on some imported project that looks like your subject, but it was here Eclipse that didn’t see modified files. I solved the problem by delete debug directory…
Your paper solve my problem.
LikeLike
Reblogged this on SutoCom Solutions.
LikeLike
Hi Erich, great find! I expect the most common cause of the Resource name being incorrect is because the project has been renamed and the resource name has not been updated. Have you found an upstream (maybe Eclipse Platform or CDT) bug or filed one?
cheers john
LikeLike
Hi John,
I searched for an existing CDT or Eclipse issue around this, but was not able to find it. I planned to file a bug, but had not done that yet.
Erich
LikeLike
Hi Erich, I couldn’t find one either. I’ll keep a look out for your bug and +1 it.
cheers john
LikeLike
I found the following CDT bugzilla regarding this:
Bug 415531 – Refrech Policy resources not tracked through rename.
I’ve updated with some of my own observations:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=415531#c1
LikeLike
Fantastic thanks. Just what I needed. The full build on each change was driving me crazy
LikeLike
Yes, that one took a while for me to find out the root cause, and I learned a lot about the internals of the build system too 🙂
LikeLike
Pingback: Kinetis Drone: Sensor Fusion Toolbox | MCU on Eclipse
Hi Erich,
I’ve had this issue on a project where there was no folder in refresh policy. Adding the folder was not sufficient. I have solved it by building 3 times:
first with the folder (all unmodified files were recompiled)
second without (all unmodified files were recompiled)
then finally with the folder. And then only it worked.
Does that makes sense to you ?
Regard
LikeLike
Hi Remi,
no, that does not make sense to me. You say you have *added* the folder? You should have there just one folder, the one of the project. So you should *replace* the folder in the list.
LikeLike
Hi Erich,
Initially, there was no folder in there.
Adding it the first time did not solve the issue.
I had to build the project, then remove the folder, then re-add it. Only at this moment it worked.
Regards
LikeLike
Strange. Maybe a F5 (Refresh) would have cured it too?
LikeLike
Pingback: Renaming Eclipse CDT Projects | MCU on Eclipse
I just came here after reading https://mcuoneclipse.com/2016/01/07/renaming-eclipse-cdt-projects/.
It reminded me to mention that in SOMNIUM DRT NXP Edition we have fixed this issue.
LikeLike
Thanks for this. I had exactly he same problem. In my case, I suspect it was because I had copy and pasted another project in workspace, and ended up with the wrong folder specified in the refresh policy settings.
LikeLike
Hi John,
I have seen many silicon vendor provided example projects having this issue: obviously the FAE or the that group copied projects around and renamed them without knowing what they are doing :-(.
LikeLike
Yup solved it for me as well. Thanks a bunch.
As per usual Eclipse standard the bug referenced by john moule has been opened for years. I always wonder what really changes between Eclipse major versions (except for the name and start up image). That being said I still find it the best all-round IDE for C development.
LikeLike
Hi Claus,
yes, some issues are lingering around for years and are not fixed :-(.
Erich
LikeLike
Sincere thanks for your most excellent detective work. Very much appreciated.
JB.
LikeLike
thanks! And that one was not easy to find.
LikeLike
Eclipse (Mars V4.5.2) fails to update “Refresh Policy” both when renaming projects and when copying and pasting them.
These are not unusual operations. For example, I do them frequently whilst learning new microcontrollers, with many new projects starting out as renamed copies of existing ones.
I’m currently learning STM32F7xx + SW4STM32 + STM32Cube + LwIP + RTOS, and even with an i7 and SSD was spending most of my time waiting for Eclipse. Your find has increased my rate of progress enormously.
Thanks again!
JB.
LikeLike
Thank you, this has driven me mad for years! I usually resort to all kinds of contortions like deleting my projects and reimporting them etc. I have linked to your blog from here: https://stackoverflow.com/questions/43487760/lpcxpresso-started-rebuilding-my-entire-project-every-time-i-do-a-regular-build
LikeLike
Hi Wayne,
great, thank you! I know that especially this issue has been a pain in many Eclipse distributions for years.
Erich
LikeLike
Pingback: Tips for Making Copy of Eclipse CDT Projects Easier | MCU on Eclipse
Thanks Erich! Your blog is extremely helpful. This worked for me and was a PAIN!!! 🙂 Much appreciated!!!!
LikeLike
You are welcome! Glad you have found that article, because I know it is not easy to search for the solution if not really knowing what the problem is.
LikeLike
Thank you!
Had I found your blog yesterday, that day would be less painful 🙂
LikeLike
Yes, I know, this one is especially painful and hard to identify.
LikeLike
Dragging up an old post! I’ve been trying the Mac version of MCUXpresso recently and had this “rebuild all every time” issue. I’d imported a project that worked fine in Windows but was doing full rebuild in Mac.
Finding this article, and checking “refresh policy” it’s blank (nothing listed) in both Windows and Mac, so apparently Windows treats that as “finished” while Mac treats it as “not finished” in some weird way!
All sorts of other Mac / Windows issues too, but they don’t belong here.
LikeLike
strange. But as as don’t own a Mac, I cannot check. Maybe there is something wrong with the file dates (maybe just a lucky punch)? Other than that: does it happen just for that project or for others (what would be the difference)? Maybe it is one of these forward/backward slashes problem?
LikeLike
All of my MCUXpresso Windows projects have the refresh policy empty with nothing listed. On the Mac side I have a couple brought in sample projects which came in with the refresh policy set like you describe here – and I was forced to do the same in the test project I copied over from Windows.
LikeLike
So it seems the curiosity is why the Windows version is perfectly happy with nothing listed in the refresh policy (good news for me!)
LikeLike
I would say that having nothing in there is not ok. It should list its own project. I only can speculate why this would result in different behaviours on Win and Linux. But my guess is that all this ‘check for time stamp’ is heavily OS related, and it seems that Windows deals with this for sure differently, and somehow it works. So: does it work if you have the project listed on Mac in the dependency?
LikeLike
Yes, that’s what I did to get it to behave properly
LikeLike
thanks for the confirmation!
LikeLike
PS: I tried the “internal builder” but then the pre / post build steps don’t seem to work!
LikeLike
Pingback: Tutorial: Rename, Copy or Clone Eclipse Projects with MCUXpresso | MCU on Eclipse