這里我介紹兩種方法,一是直接ccmake配置,二是修改cmake文件下面的CMakeList.txt文件
第一種方法:配置ccmake
1、安裝sudo apt-get install cmake-curses-gui,這是一個可視化的配置cmake,這種方式編譯后的.so文件非常小
2、下載protobuf-cpp-3.5.0.tar.gz解壓
3、cd protobuf-3.5.0
4、mkdir build
5、cd build
6、ccmake ../cmake這里會彈出一個界面,
7、Press c進行配置,配置完成彈出一個配置界面,大家根據自己的需要進行配置即可
8、配置完成再次Press c保存配置,這時會有一個Press g生成並退出
9、make -j2
10、make install
11、完成后執行protoc --version有可能會出現bash:protoc:command not found,需要把生成的protoc拷貝到/usr/bin/目錄下
第二種方法修改CMakeList.txt文件
1、下載protobuf-cpp-3.5.0.tar.gz解壓
2、cd protobuf-3.5.0
3、cd cmake
4、vim CMakeList.txt
5、在Options選項的最下方添加
set(CMAKE_BUILD_TYPE RELEASE)
set(CMAKE_INSTALL_PREFIX "/usr/local/lib")
set(protobuf_BUILD_EXAMPLES OFF)
set(protobuf_BUILD_SHARED_LIBS ON)
set(protobuf_BUILD_TESTS OFF)
set(protobuf_INSTALL_EXAMPLES OFF)
set(protobuf_MSVC_STATIC_RUNTIME OFF)
set(protobuf_WITH_ZLIB ON)
6、cd ../回到protobuf-3.5.0創建build文件夾
7、cd build
8、cmake ../cmake ////這里就是使用cmake編譯cmake目錄下的CMakeList.txt
9、make -j2
10、完成