protobuf遇坑总结

   在一个vs2013解决方案下创建了三个工程文件,在其中一个工程(Foundation)中放有CtrlMessage.pb.h和ControlMessageTags的头文件。编译后出错总共68处。

错误 2 error LNK2019: 无法解析的外部符号 "void __cdecl google::protobuf::internal::VerifyVersion(int,int,char const *)" (?VerifyVersion@internal@protobuf@google@@YAXHHPBD@Z),该符号在函数 "void __cdecl CtrlMsg::protobuf_AddDesc_CtrlMessage_2eproto(void)" (?protobuf_AddDesc_CtrlMessage_2eproto@CtrlMsg@@YAXXZ) 中被引用 F:\StartServer2013\StartServer\Foundation.lib(CtrlMessage.pb.obj) ControlCenter

错误 61 error LNK2001: 无法解析的外部符号 "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const google::protobuf::internal::kEmptyString" (?kEmptyString@internal@protobuf@google@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B) F:\StartServer2013\StartServer\Foundation.lib(CtrlMessage.pb.obj) ControlCenter

打开Foundation工程属性页,在“附加依赖项”增加protobuf库文件libprotobuf.lib,然后把以前用VS2010编译库文件复制Founddation同级目录下,Foundation工程编译通过。

然后在另一个引用Foundtion工程中,编译出错总共38处

错误 8 error LNK2038: 检测到“_MSC_VER”的不匹配项: 值“1600”不匹配值“1800”(StartServerDlg.obj 中) F:\StartServer2013\StartServer\Foundation.lib(common.obj) ControlCenter

错误 35 error LNK2038: 检测到“_MSC_VER”的不匹配项: 值“1600”不匹配值“1800”(StartServerDlg.obj 中) F:\StartServer2013\StartServer\Foundation.lib(stringprintf.obj) ControlCenter

然后ControlCenter项目的平台工具集改成vs2010,错误只有5个,

错误 1 error LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1600' in StartServerDlg.obj F:\StartServer2013\StartServer\Foundation.lib(CtrlMessage.pb.obj) ControlCenter

错误 3 error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) referenced in function "char * __cdecl std::_Allocate<char>(unsigned int,char *)" (??$_Allocate@D@std@@YAPADIPAD@Z) F:\StartServer2013\StartServer\Foundation.lib(CtrlMessage.pb.obj) ControlCenter

于是想到可能是由于protobuf的库文件是VS2010编译的。于是用VS2013重新打开PROTOBUF源文件重新编译2013版的protobuf,将编好的libprotobuf.lib文件复制到FOUNDATION工程目录下,依次编译foundation工程和ControlCenter工程,编译成功。总结VS2010和VS2013编译出的PROTOBUF的LIB文件不能交叉引用。

 

posted on   dingyun  阅读(5097)  评论(0编辑  收藏  举报

编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示