[CMake] Newbie question: Static linking

Sanatan Rai sanatan at gmail.com
Mon May 23 11:09:40 EDT 2011


On 23 May 2011 16:00, Michael Wild <themiwi at gmail.com> wrote:
> Everything that relies on static/global initialization to register
> factories is an implicit scheme. An explicit scheme is where the
> dependent code (e.g. the main() function) calls a function to do the
> registration.

   Ok, got you. However, would this not imply a monolithic build? How is
main to know that an object of a type belonging to a base class of interest
exists in linked library?

   As I mentioned earlier, I did this a little more explicitly in a
.NET project in the following
manner:

  * I had a factory object, whose job it was to hold creator functions
for objects of classes
    derived from a base class of interest.

 * The factory was a singleton, and had a static method that could be
called. The method loaded
   all linked assemblies, and picked out classes that were derived
from the base class.

  * Then it explicitly registered the class with the factory.

This seems to me to be a hybrid between implicit and explicit
registration. The actual mechanics
as one might imagine relied heavily on .NET reflection calls. One of
the ugliest bits of code I have
ever written.

--Sanatan


More information about the CMake mailing list