samedi 7 mai 2022

gRPC giving linkage errors in c++

I am writing a program using gRPC in the language c++. I have installed gRPC using the command brew install grpc on a MacOS I also have the most up to date version of protobuf. When I create a basic program using gRPC I compile them using the following commands:

protoc -I=$SRC_DIR --cpp_out=$DST_DIR $SRC_DIR/test.proto Which creates the test.pb.h and test.pb.cc files

Then the command protoc -I . --grpc_out=. --plugin=protoc-gen-grpc=/usr/local/Cellar/grpc/1.45.2/bin/grpc_cpp_plugin test.proto which creates the test.pb.h and test.pb.cc files

I then run the command g++ -std=c++11 -stdlib=libc++ test.cpp test.grpc.pb.cc -L/usr/local/lib -lprotobuf to compile, where the main c++ file is test.cpp I then get some of the following linkage errors:

"grpc::ClientContext::ClientContext()", referenced from:
      MathTestClient::sendRequest(int, int) in test-e2eddc.o
  "grpc::ClientContext::~ClientContext()", referenced from:
      MathTestClient::sendRequest(int, int) in test-e2eddc.o
  "grpc::CreateChannel(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<grpc::ChannelCredentials> const&)", referenced from:
      Run() in test-e2eddc.o
  "grpc::InsecureChannelCredentials()", referenced from:
      Run() in test-e2eddc.o
  "mathtest::MathRequest::MathRequest(google::protobuf::Arena*, bool)", referenced from:
      mathtest::MathRequest::MathRequest() in test-e2eddc.o
  "mathtest::MathRequest::~MathRequest()", referenced from:
      MathTestClient::sendRequest(int, int) in test-e2eddc.o

Which makes sense, judging based off the fact that in the file grcpp/impl/codgen/client_context.h the linkage errors would obviously be there because client context is defined as the following:

class ClientContext {
 public:
  ClientContext();
  ~ClientContext();

or with the CreateChannel function it is defined in create_channel.h file as

std::shared_ptr<Channel> CreateChannel(
    const grpc::string& target,
    const std::shared_ptr<ChannelCredentials>& creds);

In my main c++ file, I only use the following include from gRPC: #include <grpcpp/grpcpp.h>

Are there other include files from gRPC that I need to include which define these functions?

Aucun commentaire:

Enregistrer un commentaire