VS2019 配置 protobuf3.8.0


1、下載protobuf3.8.0

https://github.com/protocolbuffers/protobuf/releases/tag/v3.8.0

2、准備工作

解壓文件並在同級目錄建立install文件夾,用作編譯完成后方include ,lib等文件

3、編譯工作

使用VS開發人員命令行工具進入protobuf目錄,創建build目錄

D:\3rdParty\protobuf-cpp-3.8.0\protobuf-3.8.0\cmake>mkdir build & cd build
D:\3rdParty\protobuf-cpp-3.8.0\protobuf-3.8.0\cmake\build>

創建debug版本的編譯目錄:

D:\3rdParty\protobuf-cpp-3.8.0\protobuf-3.8.0\cmake\build>mkdir debug & cd debug
D:\3rdParty\protobuf-cpp-3.8.0\protobuf-3.8.0\cmake\build\debug>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../../../install ../..

3.1、創建生成的visual studio工程文件夾

D:\3rdParty\protobuf-cpp-3.8.0\protobuf-3.8.0\cmake\build>mkdir solution & cd solution 
D:\3rdParty\protobuf-cpp-3.8.0\protobuf-3.8.0\cmake\build\solution>cmake -G "Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX=../../../../install ../..

注:因為安裝了visual studio 2019而決定的,這是所謂的generator,不同編譯器是不同的,具體類型可見: http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators

通過上述步驟后,可以在響應的目錄中都生成了Makefile文件,接下來就是執行nmake進行編譯

D:\3rdParty\protobuf-cpp-3.8.0\protobuf-3.8.0\cmake\build\debug>nmake

安裝頭文件、庫文件等到指定的文件夾(install): ``` D:\3rdParty\protobuf-cpp-3.8.0\protobuf-3.8.0\cmake\build\debug>nmake install ```

至此debug版本都編譯成功,release版本同樣的操作即可。
然后將install目錄下的include、lib文件包含到工程中即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM