Linker error when compiling callback example

120 views
Skip to first unread message

Shareef Jalloq

unread,
Nov 28, 2022, 1:13:54 PM11/28/22
to grpc.io
Hi,

I've been trying to integrate the simple C++ callback example into my application to make sure I can compile it successfully before implementing my full protocol.  However, I'm getting linker errors and can't spot what I might have missed.

I've really just copied the greeter_callback_server.cc contents and put it in my app.  My linker settings look like:

-lgrpc -lgrpc++ -lgpr -labsl_synchronization -lprotobuf -lgrpc_plugin_support -L/opt/grpc/v1.50.1/lib

after having compiled and installed using CMake.

The errors I'm seeing are:

/usr/bin/ld: grpc_server.o: in function `GrpcServer::CreateServer()':
grpc_server.cc:(.text+0x2e5): undefined reference to `grpc::reflection::InitProtoReflectionServerBuilderPlugin()'
/usr/bin/ld: grpc_server.o: in function `helloworld::Greeter::WithCallbackMethod_SayHello<helloworld::Greeter::Service>::~WithCallbackMethod_SayHello()':
grpc_server.cc:(.text._ZN10helloworld7Greeter27WithCallbackMethod_SayHelloINS0_7ServiceEED2Ev[_ZN10helloworld7Greeter27WithCallbackMethod_SayHelloINS0_7ServiceEED5Ev]+0xb): undefined reference to `helloworld::Greeter::Service::~Service()'
/usr/bin/ld: grpc_server.o: in function `helloworld::Greeter::WithCallbackMethod_SayHello<helloworld::Greeter::Service>::WithCallbackMethod_SayHello()':
grpc_server.cc:(.text._ZN10helloworld7Greeter27WithCallbackMethod_SayHelloINS0_7ServiceEEC2Ev[_ZN10helloworld7Greeter27WithCallbackMethod_SayHelloINS0_7ServiceEEC5Ev]+0x26): undefined reference to `helloworld::Greeter::Service::Service()'
/usr/bin/ld: grpc_server.cc:(.text._ZN10helloworld7Greeter27WithCallbackMethod_SayHelloINS0_7ServiceEEC2Ev[_ZN10helloworld7Greeter27WithCallbackMethod_SayHelloINS0_7ServiceEEC5Ev]+0x1b1): undefined reference to `helloworld::Greeter::Service::~Service()'
/usr/bin/ld: grpc_server.o:(.data.rel.ro._ZTIN10helloworld7Greeter27WithCallbackMethod_SayHelloINS0_7ServiceEEE[_ZTIN10helloworld7Greeter27WithCallbackMethod_SayHelloINS0_7ServiceEEE]+0x10): undefined reference to `typeinfo for helloworld::Greeter::Service'
collect2: error: ld returned 1 exit status

Shareef Jalloq

unread,
Nov 28, 2022, 1:30:48 PM11/28/22
to grpc.io
Sorry, I fixed the missing reflection library, it's jus the helloworld::Greeter::Service::Service() issues.  But these are defined in the auto-generated output of the protocol buffer compiler.

Shareef Jalloq

unread,
Dec 5, 2022, 6:40:08 PM12/5/22
to grpc.io
OK, this was due to a misunderstanding of the output files produces by Bazel.

I have a proto file that defines a simple unary service.  When I compile this using Bazel and the cc_grpc_library rule, it outputs an archive library and a shared object and prints these to the terminal.  I was assuming that I just needed to pass this archive to my top level compilation flow but it seems that I need the archive AND all service.grpc.pb.{cc,h} and service.pb.{cc,h} files.  

Reply all
Reply to author
Forward
0 new messages