Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Protobuf compiler version doesn't match library version 3.6.1" when not using system Protobuf library

I am using CMake as a build tool and have pre-packaged binaries for all libraries I use in my project. One of those libraries is Protobuf and gets downloaded via Conan IO. So, I want to use the Protobuf downloaded by Conan and not the one already installed by Linux. The problem is that I get the following error when running CMake:

CMake Warning at /home/username/Documents/project/test/build/venv/lib/python3.6/site-packages/cmake/data/share/cmake-3.10/Modules/FindProtobuf.cmake:455 (message):
  Protobuf compiler version doesn't match library version 3.6.1
Call Stack (most recent call first):
  /home/username/Documents/project/test/script/cmake/Env.cmake:139 (include)
  CMakeLists.txt:6 (include)


-- Found Protobuf: /home/username/Documents/project/test/build/venv/.conan/data/Protobuf/3.6.1/project/dev/package/80043e232e8ab07f4b25e67652a9490d9ad33d91/lib/libprotobuf.so;-lpthread (found version "3.6.1") 
CMake Warning at /home/username/Documents/project/test/build/venv/lib/python3.6/site-packages/cmake/data/share/cmake-3.10/Modules/FindProtobuf.cmake:455 (message):
  Protobuf compiler version doesn't match library version 3.6.1
Call Stack (most recent call first):
  /home/username/Documents/project/test/src/shared/bysp/CMakeLists.txt:9 (find_package)

Is there a way to fix this? Is this something that can cause errors?

like image 560
JigsawCorp Avatar asked Jun 21 '19 13:06

JigsawCorp


People also ask

Is Protobuf compatible with Linux 3 figure?

With the typical linux 3 figure versions package-x.y.z, in increment in a number means as follows x+1 = compatability break. So somehow protobuf-2.n.n is being asked to talk to protobuf-3.n.n and they're incompatible.

Why can't I process Protobuf files?

You need to process your .proto files with protoc compiler built against the same protobuf library version that you are going to use at run time. I solved it in a Raspberry adding the next option to the CMake call. In my case, the problem was that cmake couldn't actually find the correct path to my Protobuf compiler.

What is this Protobuf in CMake?

Protobuf is in cmake. If there's a protobuf in your download, there could be a version mismatch. With the typical linux 3 figure versions package-x.y.z, in increment in a number means as follows x+1 = compatability break.


Video Answer


3 Answers

I solved it in a Raspberry adding the next option to the CMake call.

 -D Protobuf_PROTOC_EXECUTABLE=/usr/bin/protoc
like image 82
arhuaco Avatar answered Oct 19 '22 20:10

arhuaco


In my case, the problem was that cmake couldn't actually find the correct path to my Protobuf compiler.

If you check CMake's FindProtobuf.cmake module (/usr/share/cmake-3.13/Modules/FindProtobuf.cmake), the warning message happens here:

if(NOT "${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}" VERSION_EQUAL "${Protobuf_VERSION}")
   message(WARNING "Protobuf compiler version ${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}"
          " doesn't match library version ${Protobuf_VERSION}")
endif()

It's expected that the warning message will print out the actual Protobuf compiler version installed in your system. However, the actual version number is not part of the message.

In the FindProtobuf.cmake module, if you check some lines above when it tries to get the path to the Profobuf compiler, it does:

# Find the protoc Executable
find_program(Protobuf_PROTOC_EXECUTABLE
    NAMES protoc
    DOC "The Google Protocol Buffers Compiler"
    PATHS
    ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release
    ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug
)

There's no code later that checks whether a path could be found. The next step is executing the program and checking what's the version:

# Check Protobuf compiler version to be aligned with libraries version
execute_process(COMMAND ${Protobuf_PROTOC_EXECUTABLE} --version
                OUTPUT_VARIABLE _PROTOBUF_PROTOC_EXECUTABLE_VERSION)

if("${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}" MATCHES "libprotoc ([0-9.]+)")
  set(_PROTOBUF_PROTOC_EXECUTABLE_VERSION "${CMAKE_MATCH_1}")
endif()

And since, at least it my system, there's no protoc program (but protoc-c), this check fails and that's also the reason why the warning message doesn't print a message for the actual version of the Protobuf compiler installed in the system.

The solution is to change the find_program statement to something like:

# Find the protoc Executable
find_program(Protobuf_PROTOC_EXECUTABLE
    NAMES protoc-c protoc
    DOC "The Google Protocol Buffers Compiler"
    PATHS
    ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release
    ${Protobuf_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug
)

And remove CMakeCache.txt and CMakeFiles/ before rerunning cmake.

like image 43
Diego Pino Avatar answered Oct 19 '22 20:10

Diego Pino


Don't forget to install the compiler, on Ubuntu and Debian you should install the lib and the compiler as follows for C++:

sudo apt install libprotobuf-dev protobuf-compiler
like image 2
Santiwake Avatar answered Oct 19 '22 19:10

Santiwake