[CMake] whole archive linkage

Adam adam707blue at gmail.com
Sat Jan 24 07:21:48 EST 2015


On Sat, 2015-01-24 at 01:43 -0500, Braden McDaniel wrote:
> On Sat, 2015-01-24 at 13:41 +1000, Adam wrote:
> 
> > The library contains a static which registers itself in its
> > constructor. This problem is described here
> > http://stackoverflow.com/a/842770
> 
> As something of an aside to your question, I don't know that I accept
> that as a sane use case.  C++ doesn't guarantee that (in that example) m
> will be constructed before h.  If m is not constructed first,
> construction of h calls operator[] on an uninitialized object.
> 

I agree.  The actually legacy library I'm using has wrapped the global
map 'm' inside a singleton which I believe resolves the static ordering
issue. 

I currently have to specify something like the following for every
application that wants to use this library

target_link_libraries(
   Application
   -Wl,--whole-archive -llegacyLib -Wl,--no-whole-archive
   libA
   libB )

I was hoping there might have been a better way to do this with target
properties of legacyLib.

~Adam




More information about the CMake mailing list