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文件不能交叉引用。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM