Upp provides a nice solution to do init / deinit work of your package's static or global stuff (i.e. if it's not Plain Ol' Data and needs some function calls).
If your INITBLOCK / EXITBLOCK resides in a .cpp file and the file contains code that is actually referenced (used) somewhere else, everything works as expected, no precautions need to be taken. If not, the linker will drop the file, your init code won't be invoked.
This is because the INITBLOCK / EXITBLOCK actually registers itself in an init facility from upper Upp code. So no code ref downwards is added.
Deprecated Solution:
If nothing else references some code in the file, make it a .icpp file.
.icpp files are forced to be linked no matter what. See files description section in manual.
Solution:
Use INITIALIZE(MyName); in package header and INITIALIZER(PNGRaster) { .. } in .cpp where INITBLOCK / EXITBLOCK are. Possibly, you can replace INITBLOCK by INITIALIZER body. Including header file into main project ensures that file with INITIALIZER will be linked into binary.
|