windows下编译google-protocolbuf在Qt中使用

1.首先从Github-Protobuf下载代码,本文下载的版本号是3.1.0.

2.仔细查看各个README,有相关的资源下载和编译说明.

3.在一个方便的地方创建一个Install类型的文件夹,放置Cmake生成的工程文件相关内容,使用CMake-gui配置,生成visual studio ide工程.

CMAKE_CONFIGRATION_TYPES是工程配置类型,可以删除不感兴趣的配置.

CMAKE_INSTALL_PREFIX是导出visual studio ide项目文件的位置

根据自己的需求选择BUILD_SHARED_LIBS或者是MSVC_STATIC_RUNTIME(对应编译选项/Mtd和/Mt),二者选其一

4.Open Project直接编译工程.


将生成的protobuf的库引用项目,报如下错误:

1 error LNK2001: 无法解析的外部符号 "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string@internal@protobuf@google@@3V?$ExplicitlyConstructed@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@123@A)
2 error LNK2001: 无法解析的外部符号 "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string@internal@protobuf@google@@3V?$ExplicitlyConstructed@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@123@A)
3 error LNK2001: 无法解析的外部符号 "int google::protobuf::internal::empty_string_once_init_" (?empty_string_once_init_@internal@protobuf@google@@3HA)

需要在工程中添加预处理PROTOBUF_USE_DLLS

猜你喜欢

转载自www.cnblogs.com/linxmouse/p/8975475.html