Compiler issue when using FileDescriptor set in my own message

307 views
Skip to first unread message

Dan

unread,
May 25, 2012, 2:41:08 PM5/25/12
to prot...@googlegroups.com
Perhaps I am just missing something, however I am getting a compiler error that appears to be an issue with descriptor.pb.h.

The error is this: "protobuf_AddDesc_descriptor_2eproto is not a member of google::protobuf", called from "void MyPackageName::protobuf_AddDesc_MyMessage_2eproto()".
Basically, MyMessage looks like this:

package MyPackageName;
import "descriptor.proto";

option optimize_for = SPEED;

message MyMessage
{
    optional google.protobuf.FileDescriptorSet proto_set = 1;
}

Looking at the effect of other "import" statements I have made, it looks like the method should have been defined in descriptor.pb.h. It is not, and it does not appear that I should try to compile descriptor.proto myself.

I am using version 2.4.1 of the protobuf library, and as you've probably guessed, trying to compile C++.
Any ideas on how to fix this?

thanks in advance,
Dan

Jason Hsueh

unread,
Jun 4, 2012, 8:26:35 PM6/4/12
to Dan, prot...@googlegroups.com
The issue is import paths - the pre-generated versions of descriptor.pb.{h,cc} are generated relative to the source root. Instead of importing "descriptor.proto", you should have something like

import "google/protobuf/descriptor.proto";

This should make the code generator reference the declared functions in descriptor.pb.h. (And this way you should have separate directories for your code and the google protobuf code)


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/protobuf/-/AcHuNhBnkzgJ.
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.

Dan

unread,
Jun 5, 2012, 12:36:27 PM6/5/12
to prot...@googlegroups.com, Dan
Thanks Jason, this resolves the issue.

I actually have separate directories for the protobuf code as well as my own. I use the '-I' option when calling protoc, which I pointed at the directory containing 'descriptor.proto'. When I moved that path up two directories and made the import statement relative as you suggested the problem was resolved.

-Dan
To unsubscribe from this group, send email to protobuf+unsubscribe@googlegroups.com.

Jason Hsueh

unread,
Jun 5, 2012, 1:40:46 PM6/5/12
to Dan, prot...@googlegroups.com
I see, yeah, you typically want to have the include path for protoc by the root of your source tree, rather than enumerating all the different subdirectories you want to include. I'll make a note to find a place in the documentation to mention this; this seems to come up pretty frequently.

To view this discussion on the web visit https://groups.google.com/d/msg/protobuf/-/UYWCDtIbUPoJ.

To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages