2016-07-15 27 views
0

我一直在努力幾個小時才能使protobuf工作,但感覺就像我嘗試過的每一件事都是嘗試但我仍然無法得到它沒有這些錯誤鏈接:我使用MS Visual Studio的2015年庫和頭文件包括(如果我重命名的.lib文件,它抱怨說儘管我已經包含頭文件和庫(這是自編譯的),但連接錯誤

LNK2019 unresolved external symbol "public: __thiscall tutorial::Person_PhoneNumber::Person_PhoneNumber(void)" ([email protected]@@[email protected]) referenced in function "public: static class tutorial::Person_PhoneNumber * __cdecl google::protobuf::Arena::Create<class tutorial::Person_PhoneNumber>(class google::protobuf::Arena *)" ([email protected][email protected]@@@[email protected]@[email protected]@[email protected]@@[email protected]@Z) 
LNK2019 unresolved external symbol "public: __thiscall tutorial::Person::Person(void)" ([email protected]@@[email protected]) referenced in function "public: static class tutorial::Person * __cdecl google::protobuf::Arena::Create<class tutorial::Person>(class google::protobuf::Arena *)" ([email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@@[email protected]@Z) 
LNK2019 unresolved external symbol "public: __thiscall tutorial::AddressBook::AddressBook(void)" ([email protected]@@[email protected]) referenced in function _main 
LNK2019 unresolved external symbol "public: virtual __thiscall tutorial::AddressBook::~AddressBook(void)" ([email protected]@@[email protected]) referenced in function _main  

它無法找到)。

我試過2.6.1和3.0.0b3(protoc和libprotobuf,都是自編譯的而不是)。我自己編譯了protoc,並用它編譯了example .proto文件,但仍然無法編譯protobuf附帶的示例。我已經在調試和發佈模式下編譯了我自己的項目和protobuf,並且我已經從protobuf自己的測試項目中將的每個設置複製到我自己的項目中,但它不能編譯。

這感覺就像我錯過了一件超級簡單的事情,但我已經搜索了好幾個小時,並且找不到我做錯了什麼。

即使是像下面這樣的超級簡單文件也會產生相同的錯誤。

#include "example.pb.h" 

int main() 
{ 
    GOOGLE_PROTOBUF_VERIFY_VERSION; 
    Example ex; 
} 

還有什麼要做/嘗試?

+0

那麼,您是否驗證過這些符號是從您的LIB中導出的? [DUMPBIN](https://msdn.microsoft.com/en-us/library/c1h23y6c.aspx)是一個強大的工具。 – IInspectable

+1

可能重複[什麼是未定義的引用/未解析的外部符號錯誤,以及如何解決它?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-符號錯誤和如何-DO-修復) – Soren

回答

0

當您在example.proto上運行protoc時,它會生成兩個文件:example.pb.hexample.pb.cc。您需要將example.pb.cc編譯到您的程序中。

相關問題