使用vcpkg

如何解决使用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的二进制文件:

enter image description here

好极了!因此,现在我想尝试使用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示例文件等现有项目中。

vcpkg's installed package directory location

更新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 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-