[gRPC] Window Build (vcpkg, cmake)


1) vcpkg를 설치

1
2
git clone https://github.com/microsoft/vcpkg.git
.\bootstrap-vcpkg.bat


2) vcpkg를 환경 변수에 추가

image


3) vcpkg로 gprc 설치

1
vcpkg install grpc


설치 완료 후 vcpkg install grpc를 한번 더 입력하면 아래와 같은 메세지가 표시 됩니다.

1
2
3
4
5
6
7
8
9
10
The following packages are already installed:
    grpc:x86-windows -> 1.51.1
grpc:x86-windows is already installed
Total install time: 1.62 ms
grpc provides CMake targets:

    # this is heuristically generated, and may not be correct
    find_package(gRPC CONFIG REQUIRED)
    # note: 5 additional targets are not displayed.
    target_link_libraries(main PRIVATE gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts)


4) cmake 및 테스트 코드 작성

i) main.cpp

1
2
3
4
5
6
7
8
#include <iostream>
#include <grpcpp/grpcpp.h>

int main() 
{
    std::cout << "Hello gRPC(" << grpc::Version() << ")World" << std::endl;
    return 0;
}

ii) CMakeLists.txt

1
2
3
4
5
6
7
8
9
cmake_minimum_required(VERSION 3.0...3.27)

project(grpc-ysbaekFox-examples)

find_package(gRPC CONFIG REQUIRED)

add_executable(exec main.cpp)
target_link_libraries(exec PRIVATE gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts)


5) cmake 빌드

1
2
3
4
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE="{your-vcpkg-home-path}/scripts/buildsystems/vcpkg.cmake"
cmake --build . -j 4


6) 실행

image

Updated:

Leave a comment