Blog's Rdhafidh

Building protobuf using MinGW on Windows

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:

  1. MinGW 8.x 
  2. CMake tools for windows.
  3. A mingw32-make.exe for windows. (Normally this tool is bundled from either MinGW zip download or it's official installer)

If all of above tools is already present, then we can continue to our build process.

  1.  Create windows batch file 

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
  1. Clone protobuf repo.
git clone
  1. Open command prompt and type mingw8. Enter following commands :
cd protobuf && mkdir ..\build && cmake.exe -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%MINGWPATH%\opt -G "MinGW Makefiles" ..\protobuf\cmake && mingw32-make
  1. You'll be greeted with following errors:

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\
	C:\mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
	compilation terminated.
	mingw32-make[2]: *** [CMakeFiles/libprotobuf.dir/D_/git/protobuf/src/google/protobuf/] Error 1
	mingw32-make[1]: *** [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.


Read More →

Hello world of bloggin'

I am happy that I can release this personal blog to the public. Here I will try to share some tips from personal opinion with the hottest topics to the topic of programming languages and some free open source softwares.

(Image's courtsey of Google)







I hope you can enjoy to visit this site, thank you. smiley


Read More →