Difficulty using Protobuf 3.2 in C ++

I am trying to use Protobuf in C ++, but cannot get it to do anything meaningful. I am using Visual Studio 2015.

I built the protobuf library. I am using the latest version from github.

I created a .proto file as such:

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; } 

I will compile this and try to add it to the project:

 #include "Robot.pb.h" int main(int argc, char **argv) { Networking::Robot robot_message; return 0; } 

My link linker is libprotobuf.lib. I create it as / MD, and libprotobuf is built as / MD.

For some reason, this simple program has the following two linker errors:

 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) 

I am very confused - this is a very simple program. What can i do wrong?

EDIT: A colleague put together a proto 3001000. This version seems to work. I'm curious that about 3002000 breaks everything.

+5
source share
1 answer

If you are using a DLL, use

 #define PROTOBUF_USE_DLLS 
+2
source

Source: https://habr.com/ru/post/1265455/


All Articles