Problems linking for Android when using QT's gRPC generator.
-
I have a toy project where I simply implement a client for googles "Route Guide" example using QT 6.7.1 and QML. The program works when I Compile for desktop. When I compile for Android/x86_64, I get a link error for the gRPC library.
I'm using
qt_add_protobuf
andqt_add_grpc
in the projects CMakeLists.txt.[15/42 11.1/sec] Building CXX object src/qt_client/CMakeFiles/GrpcClient.dir/GrpcClient_autogen/mocs_compilation.cpp.o [16/42 11.8/sec] Building CXX object src/qt_client/CMakeFiles/GrpcClient.dir/route_guide_client.grpc.qpb.cpp.o [17/42 12.2/sec] Linking CXX shared library src/qt_client/libGrpcClient_x86_64.so FAILED: src/qt_client/libGrpcClient_x86_64.so
I have a similar error in a real project if I try to compile for Android.
Is this a bug, or do I need to do something special in the CMake files to make gRPC work for Android.
-
I would say you first have to compile the gRPC library for Android.
You also did not post the actual error. -
I would say you first have to compile the gRPC library for Android.
You also did not post the actual error.@jsulm Thank you. Looking deeper into the actual error message show that the generated protobuf library was not automatically linked with the generated gRPC library when compiling for Android.
Adding this to the CMakeList.txt fixed that problem.
# Existing code qt_add_protobuf(RouteGuideLib QML QML_URI routeguide.pb PROTO_FILES ${protofile} ) qt_add_grpc(GrpcClient CLIENT PROTO_FILES ${protofile} ) # added to fix the problem target_link_libraries(GrpcClient PRIVATE RouteGuideLib Qt6::Core Qt6::Protobuf Qt6::Grpc )
-