Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difficulty using Protobuf 3.2 in C++

I'm trying to use Protobuf in C++, but having trouble getting it to do anything meaningful. I'm using Visual Studio 2015.

I built the protobuf library. I'm using the latest version from github.

I have 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 compile this, and try to add it to a project:

#include "Robot.pb.h"



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

    Networking::Robot robot_message;

    return 0;

}

My linker links libprotobuf.lib. I am building 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'm very confused - this is a very simple program. What could I possibly be doing wrong?

EDIT: A colleague compiled proto 3001000. This version does seem to work. I'm curious as to what about 3002000 breaks everything.

like image 615
user650261 Avatar asked Mar 14 '17 21:03

user650261


People also ask

Does protobuf reduce size?

Protobuf messages were 9% smaller than JSON messages and they took only 4% less time to be available to the JavaScript code.

Does Google use protobuf?

Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.

What is protobuf C?

This is protobuf-c, a C implementation of the Google Protocol Buffers data serialization format. It includes libprotobuf-c , a pure C library that implements protobuf encoding and decoding, and protoc-c , a code generator that converts Protocol Buffer . proto files to C descriptor code.

How do I know what version of protobuf is installed?

To check which version of the Python library protobuf is installed, run pip show protobuf or pip3 show protobuf in your CMD/Powershell (Windows), or terminal (macOS/Linux/Ubuntu).


1 Answers

If you are using DLL, use

#define PROTOBUF_USE_DLLS
like image 172
user7795391 Avatar answered Oct 11 '22 12:10

user7795391