簡體   English   中英

不使用系統 Protobuf 庫時,“Protobuf 編譯器版本與庫版本 3.6.1 不匹配”

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

我使用 CMake 作為構建工具,並為我在項目中使用的所有庫預先打包了二進制文件。 這些庫之一是 Protobuf,可通過 Conan IO 下載。 所以,我想使用 Conan 下載的 Protobuf 而不是 Linux 已經安裝的 Protobuf。 問題是我在運行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)

有沒有辦法來解決這個問題? 這是會導致錯誤的東西嗎?

我在 Raspberry 中解決了這個問題,在 CMake 調用中添加了下一個選項。

 -D Protobuf_PROTOC_EXECUTABLE=/usr/bin/protoc

就我而言,問題在於cmake實際上無法找到我的 Protobuf 編譯器的正確路徑。

如果您檢查 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()

預計警告消息將打印出系統中安裝的實際 Protobuf 編譯器版本。 但是,實際版本號不是消息的一部分。

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
)

稍后沒有代碼檢查是否可以找到路徑。 下一步是執行程序並檢查版本:

# 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()

而且,至少在我的系統中,沒有protoc程序(但是protoc-c ),因此此檢查失敗,這也是警告消息不為系統中安裝的 Protobuf 編譯器的實際版本打印消息的原因.

解決方案是將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
)

並在重新運行cmake之前刪除CMakeCache.txtCMakeFiles/

看起來您下載的 protoc 由於某種原因無法啟動。 嘗試獲取protobuf版本

./protoc --version

在相應的目錄中。

不要忘記安裝編譯器,在 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