Projucer and Multi Target Exportes


#1

Here is an issues, that you probably to did not think about. Adding all the code into a static library seem like a smart solution, but there is one big drawback with static libraries. The pattern, where static initializers are used to implement self registering classes does not work anymore and there is not workaround on Windows that works.


#2

Can you elaborate? I’m not quite sure what you mean.


#3

If you have static variables, that are not referenced outside the static library, they are discarded by the linker, because, only what is referenced is imported from the static library. There are certain patterns, that use a constructor of a static object to perform some work, for instance registration of a class in some factory.


#4

Hmm. I’m pretty sure the compiler isn’t allowed to optimise-away static constructor code that has side-effects.


#5

I think @wkundrus is talking about this:

which is undefined behavior and there is no guarantee that it works with ANY compiler, regardless of platform.


#6

Thanks for the link. My code is different and I don’t think what is said there applies. I use this pattern for over 20 years now and it has proven to be a powerful concept. It worked on 5 different platforms and dozens of compilers.

It is just one example of code, that does not work in a static library.