天天看點

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

00. 目錄

01. protobuf源碼下載下傳

02. 安裝cmake

03. 生成動态庫

04. 添加環境變量

05. 附錄

csdn下載下傳:javascript:void(0)

下載下傳網址:https://github.com/protocolbuffers/protobuf/releases

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

2.1 cmake介紹

cmake這個名字是“cross platform make”的縮寫 。 cmake是一個跨平台的安裝編譯工具,可以用簡單的語句來描述所有平台的安裝(編譯過程)。他能夠輸出各種各樣的makefile或者project檔案,能測試編譯器所支援的c++特性,類似unix下的automake。隻是 cmake 的組态檔取名為 cmakelists.txt。cmake 并不直接建構出最終的軟體,而是産生标準的建構檔(如 unix 的 makefile 或 windows visual c++ 的 projects/workspaces),然後再依一般的建構方式使用。這使得熟悉某個內建開發環境(ide)的開發者可以用标準的方式建構他的軟體,這種可以使用各平台的原生建構系統的能力是 cmake 和 scons 等其他類似系統的差別之處。

2.2 cmake安裝

相關安裝方法請參考: 【tools】windows安裝cmake工具

3.1 解壓protobuf-cpp-3.10.0.zip到d盤

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

注意:路徑中不要有中文。

3.2 打開cmake工具

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

3.3 設定源碼路徑和生成項目的路徑

選擇配置

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

3.4 選擇vs版本和編譯器

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

3.5 選擇生成對應對應的庫

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

3.6 生成成功

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

然後選擇open project,預設使用vs2017打開該項目。

3.7 編譯項目生成庫檔案

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

在 vs2017工程目錄<code>/debug</code>目錄下,可以看到生成的庫檔案

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

将生成的動态庫和頭檔案放到自定義目錄中備用,在vs中設定頭檔案和庫的路徑。

修改預處理器定義:

項目屬性-&gt;c/c++ -&gt; 預處理器 -&gt; 預處理器定義 添加這個<code>protobuf_use_dlls</code>宏定義

4.1 将上面整理好的sdk放在c盤中

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

4.2 設定環境變量

滑鼠右擊此電腦–&gt; 屬性 --&gt; 進階系統設定 --&gt; 環境變量

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

建立兩個環境變量

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

4.3 測試

【Protocol Buffer】Protocol Buffer入門教程(八):Windows平台部署Protobuf環境

到此windows平台部署protobuf環境已經成功了。

sdk下載下傳:sdk-protobuf3.10.rar