Compiling grpc on Ubuntu 22.04 with system libprotobuf

1,364 views
Skip to first unread message

Mandeep Sandhu

unread,
Sep 16, 2024, 4:15:44 PM9/16/24
to grpc.io
Hey all,

I'm trying to build gRPC from source using this guide: https://grpc.io/docs/languages/cpp/quickstart/

I'm running Ubuntu 22.04.

One thing I'm doing differently is trying to use the system installation of libprobuf & protoc. I'm doing this because I already have a c++ application that uses protobuf & I would like grpc build to use that same installation (the grpc lib will also be used in this c++ application).

This is how I configure gRPC:

cmake -DgRPC_INSTALL=ON \
    -DgRPC_BUILD_TESTS=OFF \
    -DCMAKE_INSTALL_PREFIX="/home/mandeep/work/grpc/cmake/install" \
    -DgRPC_ZLIB_PROVIDER=package \
    -DgRPC_PROTOBUF_PROVIDER=package \
    ../..

But with this, I get the error that cmake cannot find the protobuf cmake files:

CMake Error at cmake/protobuf.cmake:58 (find_package):
  Could not find a package configuration file provided by "Protobuf" with any
  of the following names:

    ProtobufConfig.cmake
    protobuf-config.cmake

  Add the installation prefix of "Protobuf" to CMAKE_PREFIX_PATH or set
  "Protobuf_DIR" to a directory containing one of the above files.  If
  "Protobuf" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  CMakeLists.txt:377 (include)

I understand that the *.cmake files listed in the error message are not provided in any of the ubuntu-provided protobuf packages.

I did find "protobuf-config.cmake" under third_party/protobuf/cmake/protobuf, but setting that in the cmake configure step also gives an error, although this time its a different error:

-- Could NOT find utf8_range (missing: utf8_range_DIR)
CMake Error at third_party/protobuf/cmake/protobuf/protobuf-config.cmake:14 (include):
  include could not find requested file:

    /home/mandeep/work/grpc/third_party/protobuf/cmake/protobuf/protobuf-targets.cmake
Call Stack (most recent call first):
  cmake/protobuf.cmake:58 (find_package)
  CMakeLists.txt:377 (include)

Can anyone suggest whats the correct way to configure grpc build to use the system installed protobuf packages?

These are the packages install on my system:
$ dpkg -l | grep protobuf
ii  libprotobuf-dev:amd64                         3.12.4-1ubuntu7.22.04.1                           amd64        protocol buffers C++ library (development files) and proto files
ii  libprotobuf-lite23:amd64                      3.12.4-1ubuntu7.22.04.1                           amd64        protocol buffers C++ library (lite version)
ii  libprotobuf23:amd64                           3.12.4-1ubuntu7.22.04.1                           amd64        protocol buffers C++ library
ii  protobuf-compiler                             3.12.4-1ubuntu7.22.04.1                           amd64        compiler for protocol buffer definition files
ii  python3-protobuf                              3.12.4-1ubuntu7.22.04.1                           amd64        Python 3 bindings for protocol buffers

Thanks for your time

-mandeep

Mandeep Sandhu

unread,
Oct 1, 2024, 12:52:06 PM10/1/24
to grpc.io
bumping this for visibility, in case someone's got ideas on how to debug this issue further.

Michael Henke

unread,
Oct 3, 2024, 10:48:49 AM10/3/24
to grpc.io
I am having the same problem, anyone have an idea on how to move forward.?

veb...@google.com

unread,
Oct 3, 2024, 5:21:39 PM10/3/24
to grpc.io
I think that Ubuntu built-in protobuf isn't configured to support CMake. I don't think there is a way to workaround this issue other than installing Protobuf from source.

Pragadeesh nagaraj

unread,
Oct 4, 2024, 6:48:14 PM10/4/24
to Mandeep Sandhu, grpc.io
You can try specifying in CMAKE where to find the protobuf file like the below highlighted text.
cmake -DCMAKE_INSTALL_PREFIX=/usr/local \
 -DBUILD_SHARED_LIBS=ON \
 -DgRPC_INSTALL=ON \
 -DgRPC_BUILD_TESTS=OFF \ 
 -DgRPC_CPP_PLUGIN=ON \
 -DgRPC_PROTOBUF_PROVIDER=package \ 
 -DCMAKE_PREFIX_PATH=/path/to/your/protobuf \ ..

There is another option you can try as an alternative  -Dprotobuf_DIR=/path/to/your/protobuf/lib/cmake/protobuf \.  if you have protobuf cmake file available in your installation path.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/747fa34a-3d01-46f8-8aba-96f2c04ae27cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages