We have 2 libraries - Google Protobuf (version 4.2) and a library 'X'.. a particular object of X when initialized uses certain functions of protobuf, thus resulting in a crash of our application, as library X is getting linked first followed by Protobuf.. How can we ensure that library X would get linked only once Protobuf is done? Do we have some linker option/flag to do the same?

1

There are 1 answers

0
Claudio On

Yes, initialization order of different compilation units has undefined behavior. I often rely on a Singleton or a Factory to impose a proper initialization order.