简体   繁体   English

在 Linux 上使用 CMake 构建 gRPC C++

[英]Building gRPC C++ with CMake on Linux

I'm trying to build gRPC (cpp) using CMake, but running into errors.我正在尝试使用 CMake 构建 gRPC (cpp),但遇到了错误。 I am able to successfully build gRPC with make per the instructions on the gRPC cpp page .我能够按照gRPC cpp 页面上的说明使用make成功构建 gRPC。 Using make is deprecated, but CMake isn't working for me.不推荐使用make ,但 CMake 对我不起作用。

After following the instructions for downloading, cloning etc., I go to the "Building with CMake", where it says for Linux/Unix, do this:按照下载、克隆等说明进行操作后,我转到“使用 CMake 构建”,其中显示了适用于 Linux/Unix 的内容,请执行以下操作:

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

For me, it fails at the 3rd line ( cmake ).对我来说,它在第三行( cmake )失败。 The following is the output:以下是输出:

$ 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>

Those files ( cmake/<package name>.cmake ) don't exist in the cmake/ directory on my system.这些文件 ( cmake/<package name>.cmake ) 在我系统的cmake/目录中不存在。 I'm not sure what in the CMakeLists.txt file would cause them to appear there.我不确定 CMakeLists.txt 文件中的什么会导致它们出现在那里。

Researching this issue, I tried various combinations of cmake options such as -DBUILD_SHARED_LIBS=ON , -DgRPC_INSTALL=ON , and -DgRPC<package_name>_PROVIDER=package for each of the fails listed above.在研究这个问题时,我针对上面列出的每个失败尝试了各种cmake选项的组合,例如-DBUILD_SHARED_LIBS=ON-DgRPC_INSTALL=ON-DgRPC<package_name>_PROVIDER=package I always get the same errors.我总是遇到相同的错误。 Finally, I tried running the run_distrib_test_cmake.sh script.最后,我尝试运行run_distrib_test_cmake.sh脚本。 It eventually failed the same way.它最终以同样的方式失败了。

Any ideas?有任何想法吗?

The third party CMake files (eg cmake/zlib.cmake ) do exist in the GitHub repository you cloned (see here ).第三方 CMake 文件(例如cmake/zlib.cmake )确实存在于您克隆的 GitHub 存储库中(请参阅此处)。 Please be sure your repository finished cloning completely, to include all of the submodules, per the gRPC build documentation :根据 gRPC 构建文档,请确保您的存储库已完全克隆,以包含所有子模块:

Run from grpc directory after cloning the repo with --recursive or updating submodules.使用 --recursive 或更新子模块克隆 repo 后从 grpc 目录运行。

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

So be sure everything is cloned with:所以请确保所有内容都被克隆:

git checkout --recurse-submodules

or或者

git submodule update --recursive

As @squareskittles points out, the cmake directory is part of the clone.正如@squareskittles 指出的,cmake 目录是克隆的一部分。 I probably inadvertently deleted and re-created it.我可能无意中删除并重新创建了它。

Other than this, the only other thing I had to do which was not mentioned for Linux builds, was to install golang ( sudo apt-get install golang ).除此之外,我必须做的唯一一件事是安装 golang( sudo apt-get install golang ),但没有提到 Linux 版本。 This was mentioned as a prerequisite for Windows, but I think it should more accurately be described as a prerequisite for CMake builds, as it seems to be necessary for Linux, CMake builds.这被认为是 Windows 的先决条件,但我认为应该更准确地将其描述为 CMake 构建的先决条件,因为它似乎是 Linux、CMake 构建所必需的。

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

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