【发布时间】:2016-09-29 23:17:01
【问题描述】:
我遇到了与此处提到的相同的问题: Protobuf - Refuses to link vs2013 or vs2015
我发现generated_message_util.h中的这两行可能会导致这个问题:
__declspec(dllexport) extern const ::std::string* empty_string_;
__declspec(dllexport) extern ProtobufOnceType empty_string_once_init_;
见:https://github.com/google/protobuf/blob/master/src/google/protobuf/generated_message_util.h#L80
我对关键字 extern 不是很熟悉,但最后尝试使用该库的链接器找不到这些变量的两个定义,这些变量在 generated_message_util.cc 中完成.
const ::std::string* empty_string_;
GOOGLE_PROTOBUF_DECLARE_ONCE(empty_string_once_init_);
void InitEmptyString() {
empty_string_ = new string;
...
}
请参阅:https://github.com/google/protobuf/blob/master/src/google/protobuf/generated_message_util.cc#L51 和以下行。
有人知道这个问题的好解决方法吗?
【问题讨论】: