【发布时间】:2020-10-17 16:02:23
【问题描述】:
我正在尝试使用通过 vcpkg 管理器安装的 grpc 构建和运行 grpc 示例。
我通过克隆和查找 grpc 来安装 vcpkg 管理器,如下所示:
sudo apt-get install -y unzip build-essential
git clone https://github.com/microsoft/vcpkg
cd vcpkg/
./bootstrap-vcpkg.sh -disableMetrics
./vcpkg search grpc
./vcpkg install grpc
export PATH=$PATH:$HOME/vcpkg/downloads/tools/cmake-3.14.0-linux/cmake-3.14.0-Linux-x86_64/bin
太棒了!所以我想我有grpc。我还需要 protobuf,但它是随 vcpkg 的 grpc 一起安装的。如果我尝试安装 protobuf,我会得到以下输出:
an@ubuntu:~/vcpkg$ ./vcpkg install protobuf
Computing installation plan...
The following packages are already installed:
protobuf[core]:x64-linux
Package protobuf:x64-linux is already installed
Total elapsed time: 205.3 us
The package protobuf:x64-linux provides CMake targets:
find_package(protobuf CONFIG REQUIRED)
target_link_libraries(main PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite
为了仔细检查,我使用./vcpkg list 来显示我已安装的所有软件包。这是它的样子。注意:protobuf 和 grpc
adrian@ubuntu:~/vcpkg$ ./vcpkg list
abseil:x64-linux 2020-03-03#8 an open-source collection designed to augment th...
c-ares:x64-linux 2019-5-2-1 A C library for asynchronous DNS requests
grpc:x64-linux 1.31.1 An RPC library and framework
openssl-unix:x64-linux 1.1.1h OpenSSL is an open source project that provides ...
openssl:x64-linux 1.1.1g#1 OpenSSL is an open source project that provides ...
protobuf:x64-linux 3.13.0#2 Protocol Buffers - Google's data interchange format
re2:x64-linux 2020-10-01 RE2 is a fast, safe, thread-friendly alternative...
upb:x64-linux 2020-08-19 μpb (often written 'upb') is a small protobuf i...
zlib:x64-linux 1.2.11#9 A compression library
我们还可以在下面突出显示的/vcpkg/installed/x64-linux/libs 目录中看到 grpc 和 protobuf 的二进制文件:
好的,太好了!所以现在我想尝试使用 vcpkg 管理器插件编译 grpc 的 hello world 示例。在官方 grpc 网站上,他们有构建和编译的快速说明。 (默认情况下,他们在本地安装 grpc,但卸载过程很混乱,这就是我使用 vcpkg 的原因)。所以让我们尝试使用这些 instructions from grpc's quick start guide 进行编译:
mkdir -p cmake/build
pushd cmake/build
cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../..
make -j
重要的是要注意,一开始他们原生安装了 grpc(删除不喜欢的 vcpkg 很麻烦)。他们的指示表明要像这样设置MY_INSTALL_DIR:
export MY_INSTALL_DIR=$HOME/.local
export PATH="$PATH:$MY_INSTALL_DIR/bin"
但这是用于本地安装和编译 grpc 的二进制文件。不幸的是,我不知道 vckpkg 管理器的二进制文件在哪里。我看到 cmake 安装并有一个位于:vcpkg/downloads/tools 的二进制文件,但我没有看到它们各自的二进制文件的 grpc 或 protobuf 文件夹(见下图)。 vcpkg 的二进制文件位于何处?根据 grpc 的官方说明,我应该使用 cmake 并在下面定义这些。
find_package(gRPC CONFIG REQUIRED)
find_package(Protobuf CONFIG REQUIRED)
不幸的是,我对 vcpkg 和依赖项相对较新,但对使用 Makefile 有一点经验(我相信这与 cmake/cmakelists 有很大不同。我从未从头开始制作 cmake 文件,因为我主要使用 Makefile)。有人可以指出正确的方向如何使用 vcpkg 编译和运行这些示例(或提出更好的方法?)我的目标是学习如何使用 vcpkg 并将其集成到现有项目中,例如 gRPC 的示例文件。
更新 1:
我 cd 到示例 hello world 文件夹并按照建议运行以下命令:
mkdir build-dir
cd build-dir
cmake ..
make
当我运行cmake .. 时,出现以下错误:
grpc/examples/cpp/helloworld/build$ cmake ..
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:99 (message):
Could not find toolchain file: /usr/vcpkg/scripts/buildsystems/vcpkg.cmake
Call Stack (most recent call first):
CMakeLists.txt:24 (project)
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
这表明我没有使用正确的 cmake(vcpkg 使用的那个。所以我做了一点挖掘,根据这个 vcpkg documentation 我需要将 vcpkg 包与 ./vcpkg integrate install 集成,这会暴露我所有的包在我的系统上,只要我将它指向内部的 cmake。然后它说我应该播种路径:
~/vcpkg$ ./vcpkg integrate install
Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=/home/adrian/vcpkg/scripts/buildsystems/vcpkg.cmake"
所以我尝试使用 cmake .. 构建,但我提供了 DCMAKE_TOOL_CHAIN 参数,但我还是像以前一样回到原来的问题。
/grpc/examples/cpp/helloworld/build$ cmake .. "-DCMAKE_TOOLCHAIN_FILE=/home/adrian/vcpkg/scripts/buildsystems/vcpkg.cmake"
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:99 (message):
Could not find toolchain file: /usr/vcpkg/scripts/buildsystems/vcpkg.cmake
Call Stack (most recent call first):
CMakeLists.txt:24 (project)
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
【问题讨论】:
-
如果您使用
cmake,请参阅this answer -
仍然出错我用“更新 1”部分更新了帖子以解释发生了什么。我试图指出 vcpkg 附带的 make 但我遇到了类似的错误。
-
错字:指向建议使用的 vcpkg 的 cmake
-
"让我们尝试使用这些说明进行编译" 我认为您的链接已损坏,它指向的是图像,而不是说明。
-
你不会看到 grpc,因为你只安装了 protobuf,没有安装 grpc。它们应该在 vcpkg “已安装”树中,例如如果 $ 是 vcpkg 结帐,
$/installed/x64-linux/*
标签: c++ makefile cmake grpc vcpkg