Linking imported proto file to headers in CMakeLists.txt

260 views
Skip to first unread message

Eric Smith

unread,
Dec 24, 2020, 12:57:05 PM12/24/20
to grpc.io
Based on a [HelloWorld][1] from grpc, I have created a project with my own proto file. This proto file also imports another proto file in the same directory:

MainProto.proto:

    syntax = "proto3";

    package MyProject;
    option csharp_namespace = "MyProject";

    option optimize_for = SPEED;
    option cc_enable_arenas = true;
    import "google/protobuf/empty.proto";
    import "google/protobuf/timestamp.proto";
    import "google/protobuf/wrappers.proto";
    import "CommonUtils.proto";
    ....

Followed by a bunch of enums, messages and services, some of which use the enums/messages from CommonUtils.proto.

In the CMakeLists.txt file, I generate the .cc and .hh based on the MainProto.proto file. However, this does not seem to generate the necessary files for CommonUtils.proto, which are then detected as errors in MainProto.pb.h and the other generated header files.

My question is:

 1. How do I modify my CMakeLists or Makefile to also build the headers and cc files for CommonUtils?

 2. How do I link the generated files together to avoid "unresolved external symbol" errors?

I have tried replacing the proto file in my CMakeList.txt file (the lines # Proto file and # Generating source) with the CommonUtils.proto, and then replacing it and running with the original MainProto.proto, but I get a bunch of unresolved external symbol errors in the generated MainProto.pb.h for all the fields that should be imported from CommonUtils.proto.

My CMakeLists.txt is similar to the HelloWorld, with only greeter_async_client and greeter_async_server and the rest removed, and my Makefile is the same as the example. 

See my full file text in nice formatting here https://stackoverflow.com/questions/65433642/linking-imported-proto-file-in-cmakelists-txt

veb...@google.com

unread,
May 26, 2022, 6:30:26 PM5/26/22
to grpc.io
If you have two proto files, you may want to have the things done in the example twice; one for main.proto and the other for commonutil.proto.
And others are pretty regular cmake wiring; You can have a single proto target including two generated sources or two proto target having a dependency.
Reply all
Reply to author
Forward
0 new messages