i wanted to add a comment to one of the above replies but because i dont have sufficient reputation count, i am adding this as an answer. seek pardons for the same.
i am using protocol buffer 3.6.1 and i noticed some code in the generated .pb.cc files pertaining to what perhaps Kenton was pointing to.
namespace protobuf_foo_5fcp_5fplayer_5fcommon_5fevent_5ftypes_2eproto {
void InitDefaults() {
}
//...
//...
// Force AddDescriptors() to be called at dynamic initialization time.
struct StaticDescriptorInitializer {
StaticDescriptorInitializer() {
AddDescriptors();
}
} static_descriptor_initializer;
} // namespace protobuf_foo_5fcp_5fplayer_5fcommon_5fevent_5ftypes_2eproto
It seems that the global variable static_descriptor_initializer is never called.
I found this by modifying the code as follows and verifying that the introduced message to cout was never invoked !
//...
//...
#include <iostream>
// Force AddDescriptors() to be called at dynamic initialization time.
struct StaticDescriptorInitializer {
StaticDescriptorInitializer() {
AddDescriptors();
std::cout << "##################> DESCRIPTORS ADDED\n";
}
} static_descriptor_initializer;
Now i guess i have to find out whether there is a option in g++ (which i am using) to cause the 'static_descriptor_initializer' to be constructed during the application start sequence.