Server/C++

Google Protobuf - 1) 21.3 설치

Juzdalua 2024. 8. 20. 23:43

1. 구버전 다운로드

visual studio 2022를 사용중인데, 최신버전인 27.3과 구버전인 3.17이 호환되지 않는다.

무슨 에러인지는 자세히 모르겠지만...

 

그래서 결국 성공한 21.3 버전을 사용할 것이다.

 

- 실행용 파일

 

 

- 라이브러리용 파일

-> 8번과 연동

 

https://github.com/protocolbuffers/protobuf/releases?q=visual+studio&expanded=true

 

Releases · protocolbuffers/protobuf

Protocol Buffers - Google's data interchange format - protocolbuffers/protobuf

github.com

 


2. 압축 해제 후 폴더 이동

 


3. Protocol.proto 파일 생성

// Protocol.proto

syntax = "proto3"; // version
package Protocol; // namespace

message BuffData
{
	uint64 buffId = 1;
	float remainTime = 2;
	repeated uint64 victims = 3;
}

message S_TEST
{
	uint64 id = 1; // = 1 -> 첫 번째 위치. 초기값 아님
	uint32 hp = 2;
	uint32 attack = 3;
	repeated BuffData buffs = 4; // repeated -> 가변데이터
}

 

https://protobuf.dev/programming-guides/proto3/#scalar

 

Language Guide (proto 3)

Covers how to use the version 3 of Protocol Buffers in your project.

protobuf.dev

 


4. 배치파일 생성

// GenPackets.bat

protoc -I=./ --cpp_out=./ ./Protocol.proto
IF ERRORLEVEL 1 PAUSE

 

https://protobuf.dev/programming-guides/proto3/#generating

 

Language Guide (proto 3)

Covers how to use the version 3 of Protocol Buffers in your project.

protobuf.dev

 


5. 배치파일 실행

GenPackets.bat 파일을 실행하면 헤더, cc 파일이 생성된다.

 

테스트를 위해 생성된 2개 파일을 프로젝트에 복사하고 드래그해서 가져온다.

드래그 후 새 필터로 옮겼다.

 

클라이언트도 동일한 작업을 진행한다.


6. pch.h 

방금 복사한 Server, Client의 cc 파일의 속성에서 미리 컴파일된 헤더를 사용 안함으로 바꿔준다.


7. 폴더 구성

 

Client, Server 모두 포함 디렉터리, 라이브러리 디렉터리 설정한다.

 

ServerCore 설정

$(SolutionDir)Libraries\Libs\ServerCore\$(Configuration)\

 

pch.h 파일 수정

// pch.h

#pragma once

#define WIN32_LEAN_AND_MEAN             

#ifdef _DEBUG
#pragma comment(lib, "ServerCore\\Debug\\ServerCore.lib")
#pragma comment(lib, "Protobuf\\Debug\\libprotobufd.lib")
#else
#pragma comment(lib, "ServerCore\\Release\\ServerCore.lib")
#pragma comment(lib, "Protobuf\\Release\\libprotobuf.lib")
#endif 

#include "CorePch.h"

8. 라이브러리 다운로드

자신의 버전에 맞는 브랜치로 들어가서 zip파일을 다운로드한다.

 

 

https://github.com/protocolbuffers/protobuf

 

GitHub - protocolbuffers/protobuf: Protocol Buffers - Google's data interchange format

Protocol Buffers - Google's data interchange format - protocolbuffers/protobuf

github.com

 

** 여기서 다운 받은 라이브러리를 cmake 도중 에러가 난다면, 1번에 위치한 cpp 압축파일을 다운받아 9번을 실행한다.


9. cmake 다운로드

빌드를 하기 위해 다운로드한다.

 

https://cmake.org/download/

 

Download CMake

You can either download binaries or source code archives for the latest stable or previous release or access the current development (aka nightly) distribution through Git. This software may not be exported in violation of any U.S. export laws or regulatio

cmake.org

 

Generate - (에러가 난다면 무시) - 박스 해제 후 Generate

 

생성된 솔루션 파일 실행

 

Debug, Release 모드 ALL_BUILD 빌드

 

빌드해서 생성된 파일 복사하기

 

라이브러리 소스코드 복사

src/google

10. 동적 라이브러리 실행폴더로 복사하기

lib: 스태틱 라이브러리

-> 코드를 빌드할 때, 실행폴더에 포함이 되어 같이 코드가 작성된다.

 

dll: 동적 라이브러리

-> 실행파일 경로에 함께 위치해야한다. 

 

 

libprotobufd.dll 파일을 복사해서 실행폴더에 붙여넣어준다.

Debug 복사
Release 복사


11. 프로젝트 빌드

 

 

https://protobuf.dev/programming-guides/proto3/

 

Language Guide (proto 3)

Covers how to use the version 3 of Protocol Buffers in your project.

protobuf.dev