CPP Recompilations

I apologize for a newbie question; actually I even have to apologize for posting to this forum. I have diligently searched all the impressive sites dealing with the Haxe community of tools and cannot find an answer to the question of why recompilation of cpp sources seems to be necessary. I sort of suppose this is a lime question, but maybe it is an HXCPP question. It is, however, in attempting to target windows in the way suggested by OpenFl that the matter most clearly comes into view, so this is where I will try to get the answer.

Whether using the HaxeDevelop IDE, or just command line execution, it seems that if I target windows, I will see a long, long list of cpp files being compiled. OK, fair enough, the documentation does alert me to the fact that that will occur, but the surprise is that it will occur over and over again if I just try to compile the same HelloWorld example in two separate projects. Or, as my experimentation has taught me, I can induce the same result if I use the Clean Project feature inside a single project in HaxeDevelop.

In other words, it seems to me, the toolchain has no concept of libraries of pre-compiled code which only needs to be linked to specific application instances. This is so fundamental, and clearly the folks who have put man-centuries into the amazing cross-platform capabilities of the Haxe ecosystem must know all of this in their very bones, so I must imagine that I have simply not found whatever switch one is supposed to set to tell the build process to save the object files into some convenient library hierarchy rather than compiling the same code for every source project by which it may be used. Or, is there a build library step that I have not stumbled upon?

When you build the first time, it compiles source *.cpp files to object files. Doing a clean build deletes these object files, so all of the source *.cpp files need to be compile again. This is not all of the source files, mind you – the Lime shared library is precompiled – but all of the Haxe-based classes are recompiled.

By default, the next project you build has it’s own separate build directory, and so it compiles those same files again. Technically, this might be different from one project to another – there are compiler defines, and compiler architectures that can change the output – but generally speaking you are right, they are the same. After the sunk cost of building once, you should be able to benefit locally in each project from a compiler cache.

HXCPP has a HXCPP_COMPILE_CACHE variable you can set, if you prefer to change where the compiler cache directory is located. You could make this one central location, shared between multiple other projects. lime config HXCPP_COMPILE_CACHE path/for/compile/cache would set this variable for you, to be remembered for subsequent builds

EDIT: And don’t feel bad about posting! That’s why the forums are here :smile:

1 Like

Excellent, complete reply. Without going into detail concerning “code reuse” and, in many ways, the prime motivation for object oriented languages, it must be the case that base class sources remain the same across most compilations using windows and widgets. So, as soon as I can get to the development machine, I am eager to try the cache solution you have suggested.

Thanks again, and for the encouragement to ask for community help.

1 Like