在C++中使用Protobuf 3.2很困难

use*_*261 5 c++ protocol-buffers visual-studio

我正在尝试在C++中使用Protobuf,但无法让它做任何有意义的事情.我正在使用Visual Studio 2015.

我建立了protobuf .我正在使用github的最新版本.

我已经创建了一个.proto文件:

syntax = "proto3";
package Networking; 

message Robot{

message KinematicLinkProto {
    string name = 1;
    float x_pos = 2;
    float y_pos = 3;
    float z_pos = 4;
    float roll = 5;
    float pitch = 6;
    float yaw = 7;
    float x_scale = 8;
    float y_scale = 9;
    float z_scale = 10;
}

repeated KinematicLinkProto links = 1;

}
Run Code Online (Sandbox Code Playgroud)

我编译它,并尝试将其添加到项目中:

#include "Robot.pb.h"



int  main(int argc, char **argv)
{

    Networking::Robot robot_message;

    return 0;

}
Run Code Online (Sandbox Code Playgroud)

我的链接器链接libprotobuf.lib.我正在构建它/ MD和libprotobuf构建为/ MD.

出于某种原因,这个简单的程序有以下两个链接器错误:

Error   LNK2019 unresolved external symbol "private: static bool google::protobuf::io::CodedOutputStream::default_serialization_deterministic_" (?default_serialization_deterministic_@CodedOutputStream@io@protobuf@google@@0_NA) referenced in function "public: virtual unsigned char * __cdecl Networking::Robot::SerializeWithCachedSizesToArray(unsigned char *)const " (?SerializeWithCachedSizesToArray@Robot@Networking@@UEBAPEAEPEAE@Z)   


Error   LNK2019 unresolved external symbol "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) referenced in function "protected: void __cdecl google::protobuf::internal::RepeatedPtrFieldBase::Clear<class google::protobuf::RepeatedPtrField<class Networking::Robot_KinematicLinkProto>::TypeHandler>(void)" (??$Clear@VTypeHandler@?$RepeatedPtrField@VRobot_KinematicLinkProto@Networking@@@protobuf@google@@@RepeatedPtrFieldBase@internal@protobuf@google@@IEAAXXZ)   
Run Code Online (Sandbox Code Playgroud)

我很困惑 - 这是一个非常简单的程序.我怎么可能做错了?

编辑:一位同事编译了原型3001000.这个版本似乎确实有效.我很好奇3002000打破了一切.

小智 3

如果您使用 DLL,请使用

#define PROTOBUF_USE_DLLS
Run Code Online (Sandbox Code Playgroud)