简体   繁体   English

不使用系统 Protobuf 库时,“Protobuf 编译器版本与库版本 3.6.1 不匹配”

[英]"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.我使用 CMake 作为构建工具,并为我在项目中使用的所有库预先打包了二进制文件。 One of those libraries is Protobuf and gets downloaded via Conan IO.这些库之一是 Protobuf,可通过 Conan IO 下载。 So, I want to use the Protobuf downloaded by Conan and not the one already installed by Linux.所以,我想使用 Conan 下载的 Protobuf 而不是 Linux 已经安装的 Protobuf。 The problem is that I get the following error when running CMake :问题是我在运行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?这是会导致错误的东西吗?

我在 Raspberry 中解决了这个问题,在 CMake 调用中添加了下一个选项。

 -D Protobuf_PROTOC_EXECUTABLE=/usr/bin/protoc

In my case, the problem was that cmake couldn't actually find the correct path to my Protobuf compiler.就我而言,问题在于cmake实际上无法找到我的 Protobuf 编译器的正确路径。

If you check CMake's FindProtobuf.cmake module ( /usr/share/cmake-3.13/Modules/FindProtobuf.cmake ), the warning message happens here:如果您检查 CMake 的FindProtobuf.cmake模块( /usr/share/cmake-3.13/Modules/FindProtobuf.cmake ),则会在此处显示警告消息:

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.预计警告消息将打印出系统中安装的实际 Protobuf 编译器版本。 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:FindProtobuf.cmake模块中,如果您在尝试获取 Profobuf 编译器的路径时检查上面的一些行,它会:

# 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.而且,至少在我的系统中,没有protoc程序(但是protoc-c ),因此此检查失败,这也是警告消息不为系统中安装的 Protobuf 编译器的实际版本打印消息的原因.

The solution is to change the find_program statement to something like:解决方案是将find_program语句更改为find_program

# 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 .并在重新运行cmake之前删除CMakeCache.txtCMakeFiles/

Looks like your downloaded protoc can't start for some reason.看起来您下载的 protoc 由于某种原因无法启动。 Try to get protobuf version尝试获取protobuf版本

./protoc --version

in corresponding dir.在相应的目录中。

不要忘记安装编译器,在 Ubuntu 和 Debian 上,你应该为 C++ 安装 lib 和编译器,如下所示:

sudo apt install libprotobuf-dev protobuf-compiler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM