# windows qt protobuf - 選擇Go open source版本 ![](https://i.imgur.com/mNOgy91.png) - 下載線上安裝器 ![](https://i.imgur.com/N1gDOST.png) - 現在要先辦理一個帳號 ![](https://i.imgur.com/SMv7i3w.png) - 選擇等等自行選擇安裝環境 ![](https://i.imgur.com/IUclCoo.png) - 把 LTS 跟 Archive 打勾 並選擇您自己所需的版本 此處以6.1.2做為示範 ![](https://i.imgur.com/2KmOMRS.png) - 漫長的等待 ![](https://i.imgur.com/lmrQto6.png) - 安裝成功 - 到 [protobuf github](https://github.com/protocolbuffers/protobuf/releases) 下載最新版本protobuf-cpp-X.XX.X.zip - ![](https://i.imgur.com/NyLH2ub.png) - 解壓縮之後會看到一個這個資料夾 - ![](https://i.imgur.com/lskVHVF.png) - 使用 QT 開啟 Protobuf 的專案內的cmake/cmakelist.txt - ![](https://i.imgur.com/qdfRwmd.png) - 選擇一個 MinGW 做編譯 - ![](https://i.imgur.com/omsKc23.png) - 開始編譯此專案 - ![](https://i.imgur.com/jBh5aJd.png) - 記得切換至 release - ![](https://i.imgur.com/5Ugiwj3.png) - 在編譯前有幾個設定要做修正 需先在建置設定中更改 (記得要勾選 Advanced) - 將 protobuf_BUILD_TESTS 取消勾選 - 將 protobuf_BUILD_SHARED_LIBS 勾選 - 更改完畢後 記得按下 Apply Configuration Changes 之後就可開始編譯 - ![](https://i.imgur.com/uoBFqDa.png) - 如果看到這個畫面失敗,代表要關閉 TEST 步驟 - ![](https://i.imgur.com/wSihEjY.png) - 之後編譯完成後 - ![](https://i.imgur.com/8xKzF8H.png) - 剛剛的資料夾中會多一個 build-cmake-Desktop_Qt_X_X_X_MinGW_64_bit-Release 的資料夾 - ![](https://i.imgur.com/Ia5KK0w.png) - 安裝 CHOCOLATEY - 到 [CHOCOLATEY](https://chocolatey.org/install)官網安裝 照步驟安裝 - ![](https://i.imgur.com/LJhvbh3.png) - 使用 choco install protoc (記得使用管理員權限) - ![](https://i.imgur.com/I5Slqt9.png) - 接下來要將編譯完成的內容複製進系統的編譯環境中 - ![](https://i.imgur.com/0L41QZv.png) - 首先要轉移 lib 檔案有以下 - ![](https://i.imgur.com/tlcO3cD.png) - 複製以上檔案到 QT 的安裝資料夾中的 {QT版本}/mingw81_64/lib 中 - 以本網站範例,位置為 C:\Qt\6.1.2\mingw81_64\lib - ![](https://i.imgur.com/8Y6cal8.png) - 接下來轉移 protobuf 的所需的檔案 - 回到 protobuf 的原始碼專案中,進去 src 資料夾 - ![](https://i.imgur.com/IvQnlh6.png) - 直接複製內部的 google 這整個資料夾 - ![](https://i.imgur.com/5ErFsk5.png) - 複製到 QT 的安裝資料夾中的 {QT版本}/mingw81_64/include 中 - 以本網站範例,位置為 C:\Qt\6.1.2\mingw81_64\include - 之後在開發 protobuf 專案時,需再您的專案中的 CMakeList.txt 中 加入此行 ``` c include_directories(${Protobuf_INCLUDE_DIRS}) ``` - ![](https://i.imgur.com/rpilV3a.png) - 之後就可以開始在 windows 的 QT 上使用 Protobuf 了