如何解决使用vcpkg
我正在尝试使用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文件,因为我主要使用Makefiles)。有人可以向我指出正确的方向,如何使用vcpkg编译和运行这些示例(或提出更好的方法吗?)我的目标是学习如何使用vcpkg并将其集成到gRPC示例文件等现有项目中。
更新1:
我进入示例hellow 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使用的cmake。所以我做了一些挖掘,根据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,errors occurred!
解决方法
似乎我导出了vcpkg目录中的cmake的 错误版本 。
我导出了3.14.0,这是我的ubuntu附带的默认cmake版本,而不是vcpkg附带的cmake版本3.17.2附带的cmake。下面解决了我的问题,因此我可以随后编译示例。
export PATH=$PATH:$HOME/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin
检查并确保已将其添加到路径:
a@ubuntu:~/grpc/examples/cpp/helloworld/build$ echo $PATH | grep cmake
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/adrian/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin
将CD复制到grpc的示例hello world文件夹并进行编译:
a@ubuntu:~/grpc/examples/cpp/helloworld$ mkdir build
a@ubuntu:~/grpc/examples/cpp/helloworld$ mkdir build
a@ubuntu:~/grpc/examples/cpp/helloworld$ cd build/
a@ubuntu:~/grpc/examples/cpp/helloworld/build$ cmake .. "-DCMAKE_TOOLCHAIN_FILE=/home/adrian/vcpkg/scripts/buildsystems/vcpkg.cmake"
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.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
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
CMake Warning (dev) at /home/adrian/vcpkg/installed/x64-linux/share/protobuf/protobuf-options.cmake:6 (option):
Policy CMP0077 is not set: option() honors normal variables. Run "cmake
--help-policy CMP0077" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
For compatibility with older versions of CMake,option is clearing the
normal variable 'protobuf_MODULE_COMPATIBLE'.
Call Stack (most recent call first):
/home/adrian/vcpkg/installed/x64-linux/share/protobuf/protobuf-config.cmake:2 (include)
/home/adrian/vcpkg/installed/x64-linux/share/protobuf/vcpkg-cmake-wrapper.cmake:13 (_find_package)
/home/adrian/vcpkg/scripts/buildsystems/vcpkg.cmake:481 (include)
CMakeLists.txt:103 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Using protobuf
-- Found ZLIB: /home/adrian/vcpkg/installed/x64-linux/debug/lib/libz.a (found version "1.2.11")
-- Found OpenSSL: /home/adrian/vcpkg/installed/x64-linux/debug/lib/libcrypto.a (found version "1.1.1h")
-- Found c-ares: /home/adrian/vcpkg/installed/x64-linux/share/c-ares/c-ares-config.cmake (found version "1.15.0")
-- Using gRPC 1.31.1
-- Configuring done
-- Generating done
-- Build files have been written to: /home/adrian/grpc/examples/cpp/helloworld/build
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。