0

I installed protoc, protoc-c, libprotobuf and libprotobuf-c on my system. I have .proto file that imports timestamp.proto as follows:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

message DeviceCtx {

    google.protobuf.Timestamp CID = 1;

    uint32 ContextLen = 2;

    bytes ContextBuf = 3;

}

Am using protoc-c to generate the C binding for the same using below:

home>protoc-c --c_out=. a.proto
home>ls a.pb-c*
a.pb-c.c a.pb-c.h

It generates the C bindings for this proto file. But when I try compiling this .c file, I get the following error as it is looking for timestamp.pb-c.h file.

home>gcc a.pb-c.c dummy.c -I/usr/local/include -L/usr/local/lib -lprotobuf-c
In file included from a.pb-c.c:9:0:
a.pb-c.h:17:10: fatal error: google/protobuf/timestamp.pb-c.h: No such file or directory
#include "google/protobuf/timestamp.pb-c.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

With protoc-c I don't see the header files for standard proto like timestamp.proto being generated/staged when I installed the protoc-c. Does that mean we have to explicitly recompile all the protos under google/protobuf using protoc-c to generate the C binding for all the protos (google/protobuf/*.protos), stage the generated header files under /usr/local/include/google/protobuf and include *pb-c.c files in our library make for it to build successfully? Do I need to install any specific package to get the C bindings for protos under google/protobuf. Did I miss some step during install, which would have done the autogeneration of C bindings for all protos under google/protobuf and staged it correctly.

I don't see any issues if I don't import any protos from google/protobuf.

When using protoc for the same proto file, I don't see any such issue.

home>protoc --cpp_out=. a.proto
home>g++ a.pb.cc dummy.cc -I/usr/local/include -L/usr/local/lib -lprotobuf
home>

I am new to protobuf and using protoc-c compiler for the first time. So apologize for my shortcomings.

Thanks, -Mini

1 Answer 1

0

Usually in 3rd party protobuf libraries, you would treat the Google's .proto files the same as you would any .proto you write yourself. So you would write rules to compile them to a folder in your project-specific include directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.