Shub
Shub

Reputation: 1

Static Initialization order fiasco: how can we ensure that library X would get linked only once Protobuf is done?

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?

Upvotes: 0

Views: 144

Answers (1)

Claudio
Claudio

Reputation: 10947

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.

Upvotes: 1

Related Questions