GRPC编译安装及测试

一、安装grpc

安装grpc指令,官网链接:https://github.com/grpc/grpc/blob/master/BUILDING.md

下载源码

git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc
cd grpc

# 更新子模块
git submodule update --init

 

编译和安装

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

生成的产物

二、测试helloworld

编译测试Demo

测试helloworld编译报错找不到插件,如下图:

 发现在安装grpc时,build目录下有生成grpc_cpp_plugin,就将其拷贝到系统环境下

cp -r /home/grpc/cmake/build/grpc_cpp_plugin /usr/local/bin/

三、缺少头文件

 通过查询find / -name mutex.h,得知该文件在grpc安装目录下

 缺少系统头文件

解决:

cp -r /home/grpc/third_party/abseil-cpp/absl /usr/local/include/

ok! 搞定!

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 Windows 上编译 gRPC 的详细步骤: 1. 安装 Git 和 Visual Studio 在 Windows 上编译 gRPC,您需要先安装 Git 和 Visual Studio。您可以从以下链接下载和安装它们: - Git:https://git-scm.com/downloads - Visual Studio:https://visualstudio.microsoft.com/downloads/ 2. 克隆 gRPC 代码库 打开 Git Bash 或者其他命令行工具,输入以下命令来克隆 gRPC 代码库: ``` git clone -b v1.38.x https://github.com/grpc/grpc.git ``` 3. 安装依赖库 在 Windows 上编译 gRPC,您还需要安装一些依赖库,包括 OpenSSL 和 protobuf。您可以使用 vcpkg 工具来安装它们。以下是安装步骤: - 下载 vcpkg 工具:https://github.com/microsoft/vcpkg - 打开命令行工具,进入 vcpkg 目录,使用以下命令安装 OpenSSL 和 protobuf: ``` .\vcpkg.exe install openssl:x64-windows protobuf:x64-windows ``` 4. 生成 Visual Studio 解决方案和项目 进入 gRPC 代码库的根目录,在命令行工具中输入以下命令来生成 Visual Studio 解决方案和项目: ``` mkdir cmake_build cd cmake_build cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_TOOLCHAIN_FILE=..\third_party\vcpkg\scripts\buildsystems\vcpkg.cmake -DgRPC_SSL_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package .. ``` 5. 构建 gRPC 打开生成的 Visual Studio 解决方案,选择 "Release" 配置,然后构建 gRPC 项目。 您可以使用 Visual Studio 中的菜单或者使用以下命令来构建: ``` cmake --build . --config Release ``` 6. 运行测试 构建完成后,在命令行工具中输入以下命令来运行 gRPC测试: ``` cd grpc cmake --build . --config Release --target grpc_cli cd cmake_build ctest -C Release --output-on-failure -j 4 ``` 以上就是在 Windows 上编译 gRPC 的步骤。注意,实际情况可能会因不同的环境而有所不同,这只是一个简单的指南。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值