Here’s what worked for me:
-
You need to install MSYS with mingw. This is a minimal unix-like shell environment that lets you configure/make most unix packages. Read the mingw docs on how to install that (either with mingw-get or the GUI installer).
-
Once you have installed MSYS, you should have a shortcut in your start menu, named “MinGW Shell”. That opens a console with a bash.
-
Extract the source tarball to your MSYS home directory. I have mingw installed in “D:\prog”, so the directory was “D:\prog\MinGW\msys\1.0\home\<username>”. You can tell your MSYS username from the shell prompt. When done, you should have a directory “D:\prog\MinGW\msys\1.0\home\<username>\protobuf-2.4.1”.
-
At the shell prompt, change to the protobuf directory:
cd protobuf-2.4.1
-
Run the configure script (note the backquotes):
./configure --prefix=`cd /mingw; pwd -W`
The
--prefix
paramater makes sure protobuf is installed in the mingw directory tree instead of the MSYS directories, so you can build outside the MSYS shell (e.g. with CodeBlocks…) -
Run make:
make
-
Install:
make install
-
That’s it. You should now be able to compile your project with protobuf.
You should be able to:- call
protoc
from your project/makefiles #include <google/protobuf/message.h>
etc.- link with
-lprotobuf
or-lprotobuf-lite
- call
HTH
Peter
Edit:
Bringing this a bit more up to date. I tried setting up a new PC with current versions of MinGW and protobuf 2.5.0, and these are the problems I had:
-
There is no “MinGW Shell” shortcut in the start menu.
For some reason current MinGW installations fail to install that.
But there is amsys.bat
in<Mingw home>\msys\1.0
which brings up a console with a bash. Create a shortcut to that batch file somewhere. -
gcc does not work from the MSYS shell.
I had to run a post-installation batch file manually and answer the questions there. This sets up fstab entries that mount the mingw directories in the MSYS environment.
You need to run<Mingw home>\msys\1.0\postinstall\pi.bat
-
My Avira antivirus interfered with the protobuf compilation.
It complained about the generated protoc.exe being a “TR/Crypt.XPACK.Gen” trojan and blocked acces to that file, resulting in a corrupted build.
I got error messages saying something likeprotoc:./.libs/lt-protoc.c:233: FATAL: couldn't find protoc.
when trying to start protoc.
I had to disable the Avira realtime scanner andmake clean && make && make install
again
Edit #2:
This post has aged quite a bit, and mingw does not equal mingw anymore.
In this day and age, I would rather recommend MSYS2 which comes with a port of ArchLinux’s pacman package manager, a recent, better-working (c++11 std::thread support!) mingw fork for both 32 and 64 bit, and a protobuf package that you just need to install and be good.
Go here to download!
Hope this helps!
Peter