compile and install protobuf-cpp on windows 10


Series

Guide

compile

git clone https://github.com/protocolbuffers/protobuf.git     
cd protobuf
git submodule update --init --recursive
# third_party/benchmark third_party/googletest

cd cmake && mkdir build && cd build && cmake-gui ..

with options

CMAKE_INSTALL_PREFIX C:/Program Files/protobuf
protobuf_BUILD_SHARED_LIBS ON

Static Linking vs DLL

Static linking is now the default for the Protocol Buffer libraries. Due to issues with Win32’s use of a separate heap for each DLL, as well as binary compatibility issues between different versions of MSVC’s STL library, it is recommended that you use static linkage only.
However, it is possible to build libprotobuf and libprotoc as DLLs if you really want. To do this, do the following:

  • Add an additional flag -Dprotobuf_BUILD_SHARED_LIBS=ON when invoking cmake
  • Follow the same steps as described in the above section.
  • When compiling your project, make sure to #define PROTOBUF_USE_DLLS.

compile ALL_BUILD with VS 2015 and install to C:/Program Files/protobuf with dynamic libraries.

usage

protoc --cpp_out=. ./point_cloud.proto 
protoc --java_out=./java/ ./proto/helloworld.proto
protoc --go_out=./go/ ./proto/helloworld.proto

CMakeLists.txt

find_package(Protobuf REQUIRED)
add_definitions( -DPROTOBUF_USE_DLLS ) 
MESSAGE( [Main] " PROTOBUF_INCLUDE_DIRS = ${PROTOBUF_INCLUDE_DIRS}")   
MESSAGE( [Main] " PROTOBUF_LIBRARIES = ${PROTOBUF_LIBRARIES}")  

Reference

History

  • 20181029: created.

Author: kezunlin
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source kezunlin !
评论
  TOC