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

时间:2019-06-21 13:36:05

标签: c++ cmake protocol-buffers

我正在使用CMake作为构建工具,并且为我在项目中使用的所有库提供了预打包的二进制文件。这些库之一是Protobuf,可通过Conan IO下载。因此,我要使用柯南下载的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)

是否可以解决此问题?这会导致错误吗?

3 个答案:

答案 0 :(得分:4)

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

import 'package:flutter/material.dart';

final _someKey = UniqueKey();

void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(home: MyHomePage());
}
class MyHomePage extends StatefulWidget {
  MyHomePage();
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) => Scaffold(
      appBar: AppBar(title: Text("Problem: UniqueKey not working")),
      body: ContentHider(
        child: Column(children: [
          // This Slider DOES change when hiding/unhiding
          // This Slider SHOULDN'T change
          CustomWidget(
            key: _someKey,
          ),
        ]),
      ));
}

// When pressing the button the "child" gets rendered / not rendered
class ContentHider extends StatefulWidget {
  final Widget child;
  ContentHider({this.child});
  @override
  _ContentHiderState createState() => _ContentHiderState();
}

class _ContentHiderState extends State<ContentHider> {
  bool hidden = false;
  @override
  Widget build(BuildContext context) => Center(
        child: Column(
          children: [
            RaisedButton(
              onPressed: () {
                if (hidden == false)
                  setState(() => hidden = true);
                else
                  setState(() => hidden = false);
              },
              child: Text("Hide/Unhide"),
            ),
            hidden ? Container() : widget.child
          ],
        ),
      );
}

// StatfulWidget which contains changable content -> Slider
class CustomWidget extends StatefulWidget {
  CustomWidget({Key key}) : super(key: key);
  @override
  _CustomWidgetState createState() => _CustomWidgetState();
}

class _CustomWidgetState extends State<CustomWidget> {
  double _currentSliderValue = 0.0;
  @override
  Widget build(BuildContext context) {
    return Card(
      color: Color(0xFFACFFBC),
      child: Slider(
      value: _currentSliderValue,
      min: 0,
      max: 100,
      label: _currentSliderValue.round().toString(),
      onChanged: (double value) {
        setState(() {
          _currentSliderValue = value;
        });
      },
      ),
    );
  }
}

答案 1 :(得分:0)

看起来您的下载协议由于某种原因而无法启动。尝试获取protobuf版本

./protoc --version

在相应目录中。

答案 2 :(得分:0)

在我的情况下,问题是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 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.txt CMakeFiles /