본문 바로가기
IT

gRPC 설치 - c++

by Dblog 2021. 6. 1.
728x90

 

아래 링크를 따라서 설정합니다.

https://grpc.io/docs/languages/cpp/quickstart/

 

Quick start

This guide gets you started with gRPC in C++ with a simple working example.

grpc.io

 

개발환경

  • ubuntu 20.04
  • cmake 3.20.1
  • c++11

 

환경변수를 설정하는 부분으로 따로 고민할 필요 없이 명령어를 복사 붙여넣기 하면 된다.
추후에 테스트 혹은 protoc 컴파일 할때 환경변수가 달라지면 골치아픈게 많으니 가이드 대로 따라하는게 편하고 좋다.

https://grpc.io/docs/languages/cpp/quickstart/

 

라이브러리 설치

중간 중간 의존성에 문제가 생기면 에러메시지를 확인하며 설치

$ sudo apt install -y build-essential autoconf libtool pkg-config libssl-dev openssl git g++ cmake curl wget

 

cmake 버전 확인

$ cmake --version
cmake version 3.19.6

저번이 3.19.6이하라면 아래 링크를 따라간다.

https://cmake.org/install

 

Installing | CMake

Installing CMake There are several ways to install CMake, depending on your platform. Windows There are pre-compiled binaries available on the Download page for Windows as MSI packages and ZIP files. The Windows installer has an option to modify the system

cmake.org

 

사진에 있는  .tar.gz파일을 다운 받는다.

$ curl -OL https://github.com/Kitware/CMake/releases/download/v3.20.1/cmake-3.20.1-SHA-256.txt
$ curl -OL https://github.com/Kitware/CMake/releases/download/v3.20.1/cmake-3.20.1.tar.gz

https://cmake.org/install

 

파일을 받고나면 cmake-3.20.1.tar.gz 파일이 생기는데 압축을 풀어준다

$ tar zxvf cmake-3.20.1.tar.gz 

압축을 풀고 cmake-3.20.1 폴더로 이동하면 여러 파일이 있을텐데 아까 접속한 cmake 홈페이지에서 LINUX 설정하는 부분의 명령어를 실행한다.

$ ./bootstrap
$ make
$ make install

$ cmake .
$ make
$ make install

$ env CC=cc CXX=CC ./bootstrap
$ make
$ make install

 

여기 까지 했으면 이제 gRPC를 설치할 준비가 완료 되었다.

설치를 위해 gRPC repo를 다운 받는다.

$ git clone --recurse-submodules -b v1.37.1 https://github.com/grpc/grpc

 

Protocol Buffer, Abseil 설치

Protocol Buffer랑 Abseil을 설치한다고 하고 빌드한다고 하는데 Protocol Buffer는 RPC가 사용하니까 설치한다고 하지만 Abseil은 뭔지 모르겠다.

근데 gRPC에는 Abseil C++ library를 사용한다고 하니 설치는 해야되는 것 같다.

https://grpc.io/docs/languages/cpp/quickstart/

 

$ cd grpc
$ mkdir -p cmake/build
$ pushd cmake/build
$ cmake -DgRPC_INSTALL=ON \
            -DgRPC_BUILD_TESTS=OFF \
            -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
            ../..
$ make -j
$ make install

$ popd
$ mkdir -p third_party/abseil-cpp/cmake/build
$ pushd third_party/abseil-cpp/cmake/build
$ cmake -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
            -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
            ../..
$ make -j
$ make install
$ popd

 

여기까지 설치하면 gRPC 설정은 끝난것 같다

 

빌드 테스트

아래 예제소스까지 테스트 해보고 다음 탭인 Basics tutorial 에 있는 명령어인

$ protoc -I ../../protos --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../../protos/route_guide.proto
$ protoc -I ../../protos --cpp_out=. ../../protos/route_guide.proto

까지 실행이 가능한지 확인이 필요하다. 명령어 실행 결과로

route_guide.grpc.pb.cc
route_guide.grpc.pb.h
route_guide.pb.cc
route_guide.pb.cc   

이 4개가 추출되는 것을 확인하면 될 것 같다.

728x90

'IT' 카테고리의 다른 글

gRPC 테스트 C++  (0) 2021.06.07
gRPC 테스트 python  (0) 2021.06.01
[LINUX] 리눅스 명령어,  (0) 2021.03.18
[Docker] 삽질의 역사(1) 명령어  (0) 2021.03.15
[스코페2021]!!!  (0) 2021.03.12

댓글