protobuf_AssignDescriptors_once_ redefined?

134 views
Skip to first unread message

Adam Schepis

unread,
Mar 29, 2010, 9:44:16 PM3/29/10
to Protocol Buffers
Having an error using code generated by protobuf (c++) version 2.2.0.
I include a bunch of generated .pb.cc files generated from .proto
files, none of which have packages defined.

as a result i'm getting a bunch of strange errors:
Error 1 error C2086: 'google::protobuf::GoogleOnceType `anonymous-
namespace'::protobuf_AssignDescriptors_once_' : redefinition h:\src
\project\trunk\src\trayicon\RegisterUserReq.pb.cc 57 TrayIcon
Error 2 error C2084: function 'void `anonymous-
namespace'::protobuf_AssignDescriptorsOnce(void)' already has a body h:
\src\project\trunk\src\trayicon\RegisterUserReq.pb.cc 58 TrayIcon
Error 3 error C2084: function 'void `anonymous-
namespace'::protobuf_RegisterTypes(const std::string &)' already has a
body h:\src\project\trunk\src\trayicon\RegisterUserReq.pb.cc 63
TrayIcon
Error 4 error C3861: 'protobuf_AssignDescriptorsOnce': identifier not
found h:\src\project\trunk\src\trayicon\RegisterUserReq.pb.cc 64
TrayIcon
Error 5 error C3861: 'protobuf_AssignDescriptorsOnce': identifier not
found h:\src\project\trunk\src\trayicon\RegisterUserReq.pb.cc 112
TrayIcon

...and the list goes on.

My gut is telling me that this has something to do w/ the lack of
packages, but i dont want to add them to the .protos because there are
a lot of teams that depend on these .proto files and it would cause a
lot of code changes for them to have to start using the new namespace
in all the code where they use these messages. The other teams are
still using protobuf 2.0.3 which apparently doesnt have this problem.

any solutions to this or am i stuck?
Thanks!

Kenton Varda

unread,
Apr 1, 2010, 3:32:29 PM4/1/10
to Adam Schepis, Protocol Buffers
There shouldn't be any problem with omitting the package.  The declarations in your error message should not be appearing more than once.  I can't tell much from the error message.  Can you investigate the generated code and see whether it is actually double-declaring these things?  If so, please send us a sample.  But my guess is that something is weird about your environment, e.g. maybe your build system likes to concatenate multiple source files and compile them at once (some build systems do this), which doesn't work in the presence of anonymous namespaces.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Julien PONNOU

unread,
Mar 1, 2012, 9:48:18 AM3/1/12
to prot...@googlegroups.com
Hello,

I'm getting the exact same issue and I'd like to know how did you resolve it ?

Julien.

Abilash Gopinath

unread,
Nov 13, 2017, 1:52:47 AM11/13/17
to Protocol Buffers
Hi Kenton,

I am facing the same issue. In my case, I have multiple proto files created under the same package. When I add more than one proto file from the same package 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 single function.

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

Any help would be much appreciated.

Regards,
Abilash.G

Abilash Gopinath

unread,
Nov 14, 2017, 8:46:43 PM11/14/17
to Protocol Buffers
I found the problem it was a silly mistake from my side. Instead of adding the generated .pb.cc file to the project I was directly including multiple .pb.cc files on to a single .cpp file(stdafx.cpp) causing multiple definition error for common global functions.
Regards,
Abilash.G
Reply all
Reply to author
Forward
0 new messages