【问题标题】:Building gRPC C++ with CMake on Linux在 Linux 上使用 CMake 构建 gRPC C++
【发布时间】:2020-01-04 00:18:11
【问题描述】:

我正在尝试使用 CMake 构建 gRPC (cpp),但遇到了错误。根据gRPC cpp page 上的说明,我能够使用make 成功构建gRPC。不推荐使用 make,但 CMake 不适合我。

按照下载、克隆等说明进行操作后,我转到“使用 CMake 构建”,上面写着 Linux/Unix,请执行以下操作:

$ mkdir -p cmake/build
$ cd cmake/build
$ cmake ../..
$ make

对我来说,它在第 3 行 (cmake) 失败。以下是输出:

$ cmake ../..
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:138 (include):
  include could not find load file:

    cmake/zlib.cmake

< repeats above error for the following .cmake files: cares, protobuf, ssl, gflags, benchmark, address_sorting and nanopb>

这些文件 (cmake/&lt;package name&gt;.cmake) 不存在于我系统上的 cmake/ 目录中。我不确定 CMakeLists.txt 文件中的什么内容会导致它们出现在那里。

在研究这个问题时,我针对上面列出的每个失败尝试了 cmake 选项的各种组合,例如 -DBUILD_SHARED_LIBS=ON-DgRPC_INSTALL=ON-DgRPC&lt;package_name&gt;_PROVIDER=package。我总是遇到同样的错误。最后,我尝试运行run_distrib_test_cmake.sh 脚本。它最终以同样的方式失败了。

有什么想法吗?

【问题讨论】:

    标签: c++ c linux cmake grpc


    【解决方案1】:

    第三方 CMake 文件(例如 cmake/zlib.cmake)确实存在于您克隆的 GitHub 存储库中(请参阅 here)。请确保您的存储库完全完成克隆,以包含 所有 子模块,每个 gRPC 构建 documentation:

    使用 --recursive 克隆 repo 或更新子模块后从 grpc 目录运行。

    $ mkdir -p cmake/build
    $ cd cmake/build
    $ cmake ../..
    $ make
    

    所以请确保所有内容都被克隆:

    git checkout --recurse-submodules
    

    git submodule update --recursive
    

    【讨论】:

    • 感谢您的回复。我发布了一个答案,但您的回答让我查看了我的命令历史记录。我盲目地做了你提到的步骤,但没有注意到 cmake 目录作为克隆的一部分被拉下。所以我可能在某个时候删除了 cmake 目录。我的回答可能主要是一个红鲱鱼(安装protocolbuf),尽管关于golang的打嗝是真实的。我将编辑我的答案并接受这个。
    【解决方案2】:

    正如@squareskittles 所指出的,cmake 目录是克隆的一部分。我可能无意中删除并重新创建了它。

    除此之外,对于 Linux 构建,我唯一没有提到的其他事情就是安装 golang (sudo apt-get install golang)。这是作为 Windows 的先决条件提到的,但我认为它应该更准确地描述为 CMake 构建的先决条件,因为它似乎对于 Linux、CMake 构建是必需的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-14
      • 1970-01-01
      • 2013-11-14
      • 2023-04-10
      • 2019-05-31
      • 2022-08-24
      • 1970-01-01
      相关资源
      最近更新 更多