Rate This Document
Findability
Accuracy
Completeness
Readability

Installing Protobuf Source Code

In this version, you need to manually install Protobuf. You are advised to install Protobuf by compiling from source. The procedure is as follows:

  1. Download the Protobuf source package and Abseil source package and place them in the same directory.
  2. Decompress the source packages.
    tar -zxvf abseil-cpp-20230802.2.tar.gz
    tar -xzf protobuf-25.1.tar.gz
    mv abseil-cpp-20230802.2/* protobuf-25.1/third_party/abseil-cpp/
    cd protobuf-25.1
  3. Set compilation parameters. You can use --prefix to specify the installation path. You are advised to install it in a system directory.
    mkdir build && cd build
    cmake .. -DCMAKE_INSTALL_PREFIX=/usr -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_CXX_STANDARD=17
  4. Compile protoc and Protobuf runtime.
    make -j

    You can utilize multiple threads to accelerate the compilation. Set a proper value for {n} based on the device performance.

    make -j {n}
  5. Install protoc and Protobuf runtime, and update the dynamic library configuration cache.
    # For a non-root account, use sudo for the installation.
    sudo make install
    sudo ldconfig
    • If you specify the installation directory to /usr, protoc is installed in the /usr/bin directory, and libprotobuf.a and *.so are installed in the /usr/lib directory.
    • If the installation path is not a system directory, import the bin and lib paths to environment variables. The following is an example:
      # If --prefix=/path/to/protobuf is specified
      export PATH=/path/to/protobuf/bin:$PATH
      export LD_LIBRARY_PATH=/path/to/protobuf/lib:$LD_LIBRARY_PATH
  6. Check the version.
    If the version information is displayed, the installation is successful.
    protoc --version
    # libprotoc 25.1
  7. Create a symbolic link.
    1. Check the output. If the output contains keywords "version 'GLIBCXX_3.4.29' not found", go to 7.b.
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libprotoc.so.25.1.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libprotobuf.so.25.1.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_log_internal_message.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_log_internal_log_sink_set.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_flags_marshalling.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_flags_reflection.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_status.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_cord.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_cordz_handle.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_crc_cord_state.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_str_format_internal.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /usr/bin/../lib64/libabsl_synchronization.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_strings.so.2308.0.0)
      protoc: /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/bin/../lib64/libabsl_time_zone.so.2308.0.0)
    2. Create a symbolic link from /usr/lib64/libstdc++.so.6 to libstdc++.so.6.0.29 or later.

      For example, if GCC 12.3.0 has been installed, run the following command to create a symbolic link:

      sudo ln -sf /usr/local/gcc-12/lib64/libstdc++.so.6.0.30 /usr/lib64/libstdc++.so.6

      After a symbolic link is used to replace libstdc++.so, if you run commands such as yum and rpm, the symbolic link may be reset. As a result, an error is reported during firmware compilation. If the error message "version 'GLIBCXX_3.4.29' not found" is displayed, perform 7.b.