Search code examples
c++protocol-buffersprotocprotobuf-c

Including multiple proto files on to one project causes protobuf_AssignDescriptorsOnce() already has a body


I have got multiple proto files from the server created under the same package. When I add more than one of those proto files on to a project, each proto file is generating its own .pb.cc and .h files and each generated file has the below two methods. I need to include some of the generated .cc files to one of my projects which causes multiple definitions of the below two functions.

auto-generated functions causing "the function already has a body" issues are 1. protobuf_AssignDescriptorsOnce() 2. protobuf_RegisterTypes(const ::std::string&)

Making changes in the package name is obviously solving this issue but the proto file was given by the server and any change on that file could cause huge change in all the other dependant clients.

Any help to address this issue would be much appreciated.

Regards, Abilash.G


Solution

  • The issue was simple and not related to protobuf. I've included all the generated pb.cc files directly on to my 'stdafx.cpp' instead of adding the generated files as a part of projects which was causing the 'already has a body' error for the global functions.