google protobuf c++ 反射

const Descriptor *desc = DescriptorPool::generated_pool()->FindMessageTypeByName(msg_name);
assert(desc);

  上述示例代码,desc结果为空。最后在github找到答案

上面链接中给出的解答是

OK, finally I figured out that there is no black magic and it's just a linker problem, I compiled the proto sources into a static library, seems the linker automatically optimized out those objs not used when linking against the static library. I follow this thread and it fixes the problem

另外一个人提出的问题和得到的回答

Q:how to config on Visual Studio,when build a static library?

A:An alternative is to reference these protos types somewhere in your code so they don't get stripped by the linker.(意思就是在之前的代码中使用过这个proto)

猜你喜欢

转载自www.cnblogs.com/IGNB/p/12122791.html