Windows配置grpc
方法一
1. 使用git下载grph
git clone -b v1.70.0 --recurse-submodules https://github.com/grpc/grpc.git
# 指定版本下载
# git clone -b v1.41.0 https://github.com/grpc/grpc
下载速度慢可以使用国内镜像
git clone --recurse-submodules https://gitclone.com/github.com/grpc/grpc.git
1.1 更新子模块
git submodule update --init --recursive
2. 使用Cmake进行编译
2.1 GUI编译
选自己的vs版本
默认设置 (可修改文件存放位置)

2.2 命令行直接编译
mkdir -p cmake/build
cd cmake/build
cmake ../..
3. 使用Visual Studio 生成解决方法
打开项目中

右击重新生成解决方法

方法二
1. 安装 vcpkg
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat
3.配置vckg的环境变量
setx Path "%Path%;C:\new_path"
2. 使用 vcpkg 安装 gRPC
vcpkg install grpc:x64-windows
3. 安装 Protobuf
vcpkg install protobuf:x64-windows
4. 配置 CMake
在 CMakeLists.txt 中添加:
find_package(Protobuf REQUIRED)
find_package(gRPC CONFIG REQUIRED)
add_executable(my_server server.cpp)
target_link_libraries(my_server PRIVATE gRPC::grpc++ protobuf::libprotobuf)
5. 让 vcpkg 自动集成
vcpkg integrate install
6. 编译 gRPC 项目
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=D:/vcpkg/scripts/buildsystems/vcpkg.cmake
# 生成Release版本:cmake --build . --config Release -j 4
cmake --build .
测试是否安装成功
进入 示例目录 并运行 greeter_server 和 greeter_client:
cd examples/cpp/helloworld
如果你使用 CMake:
mkdir build && cd build
cmake ..
make -j # 或者使用VS生成解决方法
如果你使用 vcpkg:
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=D:/vcpkg/scripts/buildsystems/vcpkg.cmake
# 生成Release版本:cmake --build . --config Release -j 4
cmake --build . # # 或者使用VS生成解决方法
运行 gRPC 示例
cd Debug
./greeter_server
./greeter_client
Visual Studio 配置 grpc
- 配置包含目录

- 配置库目录

- 配置依赖项

2540

被折叠的 条评论
为什么被折叠?



