protobuf庫簡易清晰編譯方法


1、創建工作目錄:c:/path/to

2、下載CMake:https://cmake.org/download/
設置CMake環境變量:set PATH=%PATH%;C:\Users\Administrator\Desktop\cmake-3.16.0-win32-x86\bin

3、下載安裝git,一路默認選項:      https://git-scm.com/download/win
設置git環境變量:set PATH=%PATH%;C:\Program Files\Git\cmd

4、下載protobuf源碼:
C:\Path\to> git clone -b master https://github.com/protocolbuffers/protobuf.git

5、更新子模塊:
C:\Path\to>protobuf> git submodule update --init --recursive

6、進入源碼cmake目錄:
C:\Path\to\protobuf>cd cmake

7、創建臨時編譯目錄
C:\Path\to\protobuf\cmake>mkdir build & cd build

8、根據個人需要,創建release或者debug目錄:
release:
C:\Path\to\protobuf\cmake\build>mkdir release & cd release
C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../install ../..
debug:
C:\Path\to\protobuf\cmake\build>mkdir debug & cd debug
C:\Path\to\protobuf\cmake\build\debug>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../../../install ../..

9、創建Visual Studio solution(sln)文件:
C:\Path\to\protobuf\cmake\build>mkdir solution & cd solution
C:\Path\to\protobuf\cmake\build\solution>cmake -G "Visual Studio 15 2017" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../../install ../..

10、編譯:
C:\Path\to\protobuf\cmake\build\release>nmake    
或者
C:\Path\to\protobuf\cmake\build\debug>nmake
或者
用vs打開 sln 文件進行編譯

發佈了88 篇原創文章 · 獲贊 9 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章