Google Protocol buffer c++ link 尝试在项目中使用它时出错

Google Protocol buffer c++ link error when trying to use it in project

我正在尝试让协议缓冲区工作,但出现链接问题。

所有的错误看起来都是这样的

error LNK2019: unresolved external symbol "public: bool __cdecl google::protobuf::MessageLite::ParseFromArray(void const *,int)" (?ParseFromArray@MessageLite@protobuf@google@@QEAA_NPEBXH@Z) referenced in function "void __cdecl ReceiveRequest(bool *)" (?ReceiveRequest@@YAXPEA_N@Z)

我正在使用 visual studio pro 2013,这就是我所做的:

我编译了协议缓冲区并将libprotobuf.lib添加到项目中(Add->Existing Item->libprotobuf.lib)

我在 C/C++ -> 常规 -> "Additional Include Directories"

中添加了头文件

我已尝试以我所知道的所有不同方式添加库,但我仍然遇到这些链接错误...

知道我做错了什么吗?

//埃里克

确保您拥有适用于您的体系结构的正确库(例如 x86 / x64)。

这让我困惑了几次。

您需要在您的文件中包含 generated protocol buffer .cc(可能还有 .h)文件(即包含特定 proto 的特定 getter 和 setter 的文件) VS 项目(即在解决方案资源管理器中必须有一个小图标)否则 visual studio 将不会为其生成代码,因此没有什么可以 link 到。