[ACCEPTED]-How to build Google's protobuf in Windows using MinGW?-protocol-buffers
Here's what worked for me:
You need to install 53 MSYS with mingw. This is a minimal unix-like 52 shell environment that lets you configure/make 51 most unix packages. Read the mingw docs 50 on how to install that (either with mingw-get 49 or the GUI installer).
Once you have installed 48 MSYS, you should have a shortcut in your 47 start menu, named "MinGW Shell". That 46 opens a console with a bash.
Extract the 45 source tarball to your MSYS home directory. I 44 have mingw installed in "D:\prog", so 43 the directory was "D:\prog\MinGW\msys\1.0\home\<username>". You 42 can tell your MSYS username from the shell 41 prompt. When done, you should have a directory 40 "D:\prog\MinGW\msys\1.0\home\<username>\protobuf-2.4.1".
At 39 the shell prompt, change to the protobuf 38 directory:
Run the configure script (note 37 the backquotes):
./configure --prefix=`cd /mingw; pwd -W`
--prefixparamater makes sure 36 protobuf is installed in the mingw directory 35 tree instead of the MSYS directories, so 34 you can build outside the MSYS shell (e.g. with 33 CodeBlocks...)
That's it. You 32 should now be able to compile your project 31 with protobuf.
You should be able to:
protocfrom your project/makefiles
- link with
Edit: Bringing 30 this a bit more up to date. I tried setting 29 up a new PC with current versions of MinGW 28 and protobuf 2.5.0, and these are the problems 27 I had:
There is no "MinGW Shell" shortcut 26 in the start menu.
For some reason current 25 MinGW installations fail to install that.
But 24 there is a
<Mingw home>\msys\1.0which brings up a console 23 with a bash. Create a shortcut to that batch 22 file somewhere.
gcc does not work from the 21 MSYS shell.
I had to run a post-installation 20 batch file manually and answer the questions 19 there. This sets up fstab entries that mount 18 the mingw directories in the MSYS environment.
You 17 need to run
My Avira antivirus interfered 16 with the protobuf compilation.
It complained 15 about the generated protoc.exe being a "TR/Crypt.XPACK.Gen" trojan 14 and blocked acces to that file, resulting 13 in a corrupted build.
I got error messages 12 saying something like
protoc:./.libs/lt-protoc.c:233: FATAL: couldn't find protoc.when trying to start 11 protoc.
I had to disable the Avira realtime 10 scanner and
make clean && make && make installagain
This post has 9 aged quite a bit, and mingw does not equal 8 mingw anymore. In this day and age, I would 7 rather recommend MSYS2 which comes with 6 a port of ArchLinux's pacman package manager, a 5 recent, better-working (c++11 std::thread 4 support!) mingw fork for both 32 and 64 3 bit, and a protobuf package that you just 2 need to install and be good.
Go here to download!
Hope 1 this helps!
In my case Peter's answer did not work completely, I 6 used the latest MinGW 4.8.1 + the MSys distribution 5 (selected both MSys packages in
My problem 4 was that the prefix didn't really work, I 3 could only find the files in
C:\MinGW\msys\1.0\local . However, after 2 copying the bin / include / libs folders 1 to
c:\mingw, the installation worked for me, too.
I had the same problem and i solved it by 6 building protocol buffers using boost build. That 5 worked fine, I can provide a jamfile for 4 protocol buffers.
What I still have problems 3 with though is to extend boost build so 2 it generates cpp source files from proto 1 files, but that is another story.
Here is an answer for the present-day versions 17 of protobuf source distribution, for using 16 protobuf for C++ language in Windows. (My 15 protobuf version is 21.4- libprotoc 3.21.4)
Referring to 14 the answer by @peter-remmers
Step 0: Download protobuf 13 zip file from release page. e.g. "protobuf-cpp-3.21.4.zip"
- Extract it to a path where you want protobuf to be installed.
- Add the "src" folder path to system's environment path variables. e.g. "C:\Path-To-Protobuf\protobuf-3.21.4\src"
Step 1: Download 12 & install msys2: https://www.msys2.org/
Make sure to to do 11 these:
- Run "MSYS2 MSYS" from Start menu. Update the rest of the base packages with
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
Step 2: Add the mingw bin files' path to 10 system's environment variables.
- e.g. it was "C:\Path-To-Msys2\msys2\mingw64\bin" and "C:\Path-To-Msys2\msys2\usr\bin"
- Confirm by Checking the g++ version:
g++ --versionin the terminal (e.g. Mine is 12.1.0)
Step 3: Setting 9 Up C++ runtime with protobuf libraries:
- So, back in msys2, install protobuf's libraries:
pacman -S mingw-w64-x86_64-protobuf. Reference
- Now, change the directory to path where protobuf is installed in your system : e.g. cd "C:\Path-To-Protobuf\protobuf-3.21.4"
- Run the configure file of protobuf:
make(In case of any error with aclocal, etc. Try running
pacman -S autoconf, then try again
Step 4: That's 8 it. You should now be able to compile your 7 project with protobuf.
e.g. To compile a 6 .proto file using protoc to cpp code & header 5 files:
protoc --cpp_out=$OUTDIR example.proto
- Two files, a
pb.hfile will be generated.
- Write a cpp code to use that header file and create objects, populate data, etc.
- Compile that cpp writer file from terminal/PowerShell like:
g++ -I "C:\Path-To-Protobuf\protobuf-3.21.4\src" "Path-To-Code\writer.cpp" "Path-To-Code\example.pb.cc" -o "Path-To-Code\writer.exe" -L "C:\Path-To-Protobuf\protobuf-3.21.4\src\.libs" -lprotobuf -pthread
("-pthread" is not really 4 important at the end I guess.)
NOTE (The 3 problem I had): Order of paths of e.g. mingw 2 in system's environment variables list matters 1 very much.
More Related questions