如何强制 CMake 使用系统上安装的特殊版本的 Protobuf?

问题描述

我想将 Protobuf_INCLUDE_DIRS 设置为我选择的目录,但是,我不知道该怎么做。

$ locate FindProtobuf.cmake
/usr/share/cmake-3.16/Modules/FindProtobuf.cmake

我可以看到在 FindProtobuf.cmake 中,我们有这些:

if(Protobuf_FOUND)
    set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIR})
endif()

我希望在此处将其设置为第二个选项:

$ which -a protoc
/home/mona/anaconda3/bin/protoc
/usr/local/bin/protoc

然而,它被设置为第一个选项 /home/mona/anaconda3/bin/protoc,尽管它在 ~/.bashrc 中强制设置为第二个选项:/usr/local/bin/protoc 使用以下命令:alias protoc=/usr/local/bin/protoc

我的程序需要的版本是 3.6.1,别名 protoc=/usr/local/bin/protoc 保证了这一点。但是,ProtobufCMake 强制路径为 /home/mona/anaconda3/bin/protoc,该版本为 3.13.0。

关于我面临的问题的一点。我正在使用 openpose 并在 Ubuntu 20.04 中安装它,我正在使用 CMake。要求protobuf版本为3.6.1。

更多信息https://github.com/CMU-Perceptual-Computing-Lab/openpose/issues/1817

以下是消息:

CMake Error at /usr/share/cmake-3.16/Modules/FindProtobuf.cmake:469 (file):
  file STRINGS file "/usr/include/google/protobuf/stubs/common.h" cannot be
  read.
Call Stack (most recent call first):
  CMakeLists.txt:429 (find_package)


CMake Error at /usr/share/cmake-3.16/Modules/FindProtobuf.cmake:475 (math):
  math cannot parse the expression: " / 1000000": syntax error,unexpected
  exp_DIVIDE (2).
Call Stack (most recent call first):
  CMakeLists.txt:429 (find_package)


CMake Error at /usr/share/cmake-3.16/Modules/FindProtobuf.cmake:476 (math):
  math cannot parse the expression: " / 1000 % 1000": syntax error,unexpected exp_DIVIDE (2).
Call Stack (most recent call first):
  CMakeLists.txt:429 (find_package)


CMake Error at /usr/share/cmake-3.16/Modules/FindProtobuf.cmake:477 (math):
  math cannot parse the expression: " % 1000": syntax error,unexpected
  exp_MOD (2).
Call Stack (most recent call first):
  CMakeLists.txt:429 (find_package)


CMake Warning at /usr/share/cmake-3.16/Modules/FindProtobuf.cmake:499 (message):
  Protobuf compiler version 3.13.0 doesn't match library version
  ERROR.ERROR.ERROR
Call Stack (most recent call first):
  CMakeLists.txt:429 (find_package)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)