Published on 1 March 2019 by
This is small tips on how to build Google protobuf on windows using mingw 8.1. You can skip from
reading this tutorial and download from their binaries release instead for convenience.
Before digging into deeper compilation steps, please make sure that you had already installed of all the following tools:
If all of above tools is already present, then we can continue to our build process.
set CMAKEPATH=C:\cmake\bin set MINGWPATH=C:\mingw32 set CC=gcc set CXX=g++ SET INCLUDE=%MINGWPATH%\include;%MINGWPATH%\i686-w64-mingw32\include;%MINGWPATH%\x86_64-w64-mingw32\include;%MINGWPATH%\opt\include SET LIB=%MINGWPATH%\lib;%MINGWPATH%\i686-w64-mingw32\lib;%MINGWPATH%\x86_64-w64-mingw32\lib;%MINGWPATH%\opt\lib SET PATH=%PATH%;%MINGWPATH%\bin;%MINGWPATH%\i686-w64-mingw32\bin;%MINGWPATH%\x86_64-w64-mingw32\bin;%CMAKEPATH%;%MINGWPATH%\opt\bin and save it to c:\windows\mingw8.bat
git clone https://github.com/protocolbuffers/protobuf/
cd protobuf && mkdir ..\build && cmake.exe -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%MINGWPATH%\opt -G "MinGW Makefiles" ..\protobuf\cmake && mingw32-make
In file included from C:\mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/stl_algo.h:59, from C:\mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/algorithm:62, from d:/git/protobuf/src/google/protobuf/stubs/common.h:38, from d:/git/protobuf/src/google/protobuf/arena_impl.h:39, from d:/git/protobuf/src/google/protobuf/arena.h:51, from D:\masteraplikasi\transferh11nov\protobufgit\protobuf\src\google\protobuf\arena.cc:31: C:\mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/cstdlib:75:15: fatal error: stdlib.h: No such file or directory #inlude_next ^~~~~~~~~~ compilation terminated. mingw32-make: *** [CMakeFiles/libprotobuf.dir/D_/git/protobuf/src/google/protobuf/arena.cc.obj] Error 1 mingw32-make: *** [CMakeFiles/libprotobuf.dir/all] Error 2 mingw32-make: *** [all] Error 2
The problem is that gcc treats -isystem differently than usual -I flag. So, to fix that we make sure append following additional cmake command
for 32 build and for 64 build is like follows :
At the end, the following command is appropriate for 32 build:
cmake.exe -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES=%MINGWPATH%\i686-w64-mingw32\include -DCMAKE_INSTALL_PREFIX=%MINGWPATH%\opt ..\protobuf\cmake -G "MinGW Makefiles" && mingw32-make && mingw32-make install
I hope you enjoy it, thanks for reading.