[CMake] Newbie question: Static linking
Michael Wild
themiwi at gmail.com
Mon May 23 11:32:22 EDT 2011
On 05/23/2011 05:09 PM, Sanatan Rai wrote:
> 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
If it is acceptable to have just one "hook", just require your user to
define a specific function, e.g. registerUserFactories which you then
call. Otherwise it becomes more tricky.
Michael
More information about the CMake
mailing list