c++ - Why Clang++ doesn't run the global object constructor in another static library? -
we have library static_library.a
build clang++, , there file bar.cpp
include global object foo
.
but when use library in app layer xcode project, global object foo
constructor doesn't been called. (the global object constructor registration job, , impact app behavior.)
we think translation unit not linked executable file.
//bar.cpp in static_library.a class foo { public: foo() { std::cout << " constructor called" << std::endl; } }; foo a; // <------if function called in app layer project, // global constructor object called. foo* getinstance() { return &a; }
so there flag, can control behavior?
you need -all_load
linker flag.
this question has more details. may interested in -objc
or -force_load
.