Prashant Shubham
Prashant Shubham

Reputation: 516

How to dynamically link grpc library c++?

I am trying to dynamically link the grpc greeting_client example. I am trying to use the libgrpc++.so, libprotobuf.so.10, libgrpc.so.3,libgrpc++_reflection.so.1 files to do the linking.

I have added these files to my /usr/lib directory and now I am trying to generate executable for greeting_client.

Command I am using is: g++ hello.pb.o hello.grpc.pb.o greeting_client.o -L/usr/lib -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -ldl -o greeting_client -L/usr/local/include/google/ -L/usr/local/include/grpc -L/usr/local/include/grpc++

Error:

 /usr/bin/ld: cannot find -lgrpc++_reflection
 collect2: error: ld returned 1 exit status

I have the .so files for grpc++_reflection in /usr/lib directory. I might be missing something regarding dynamic linking. Can you please point out how to dynamically link the grpc libraries for the example?

Upvotes: 2

Views: 3799

Answers (1)

Prashant Shubham
Prashant Shubham

Reputation: 516

After some research I was able to find the solution, The problem is the linker is looking for libgrpc++_reflection.so but I had libgrpc++_reflection.so.14.0.0

A quick hack is to symlink libgrpc++_reflection.so to libgrpc++_reflection.so The answer lies in the -l option of g++, calling ld. If you look at the man page of this command, you can either do:

g++ -l:libgrpc++_reflection.so.14.0.0 [...]
or: g++ -lgrpc++_reflection.so [...] , 

if you have a symlink named libgrpc++_reflection.so in your libs path

Upvotes: 1

Related Questions