如何使用MinGW在Windows中构建Google的protobuf? [英] How to build Google's protobuf in Windows using MinGW?

查看:1718
本文介绍了如何使用MinGW在Windows中构建Google的protobuf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Codeblocks作为我的IDE与MingGW。
我试图使用google协议缓冲区,
但是我在构建protobuf时遇到了麻烦。

I'm using Codeblocks as my IDE with MingGW. I'm trying to use google protocol buffers, but I'm having trouble building the protobuf.

protobuf的自述文件说:

The readme file for protobuf says:


如果您使用Cygwin或MinGW,
遵循上述Unix安装说明。

If you are using Cygwin or MinGW, follow the Unix installation instructions, above.

Unix说明:


建立并安装C ++通讯协定运行时和协议
缓冲区编译器(protoc)执行以下命令:
$ ./configure
$ make
$ make check
$ make安装

我不知道如何在Windows
中执行这些,因为configure是一个Unix脚本和
我不知道如何执行它或其余的命令。

I don't know how to perform these in Windows because "configure" is a Unix script and I don't know how to execute it, or the rest of the commands.

有人可以更详细地解释
我可以在Windows上使用MinGW构建protobuf?

Can someone explain in more detail how I can build protobuf using MinGW on Windows?

推荐答案

这对我有用:


  1. 您需要使用mingw安装MSYS。这是一个最小的类UNIX shell环境,允许您配置/制作大多数unix软件包。

  1. 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).

安装MSYS之后,您应该有一个快捷方式在您的开始菜单中,命名为MinGW Shell。

Once you have installed MSYS, you should have a shortcut in your start menu, named "MinGW Shell". That opens a console with a bash.

将源压缩文件解压缩到MSYS主目录。我有mingw安装在D:\prog,所以目录是D:\prog\MinGW\msys\1.0\home\< username>。您可以从shell提示符下告诉MSYS用户名。完成后,您应该有一个目录D:\prog\MinGW\msys\1.0\home\< username> \protobuf-2.4.1。

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".

在shell提示下,切换到protobuf目录:

At the shell prompt, change to the protobuf directory:

cd protobuf-2.4.1

运行configure脚本(注意反引号):

Run the configure script (note the backquotes):

./ configure --prefix =`cd / mingw; pwd -W`

- 前缀 paramater确保protobuf已安装mingw目录树而不是MSYS目录,因此您可以在MSYS外部构建外壳(例如使用CodeBlocks ...)

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...)

运行make:

make

make

安装:

make install

您现在应该可以使用protobuf编译您的项目。

您应该能够:

That's it. You should now be able to compile your project with protobuf.
You should be able to:


  • 调用 protoc

  • #include< google / protobuf / message.h> 等。

  • 链接到 -lprotobuf -lprotobuf-lite

  • call protoc from your project/makefiles
  • #include <google/protobuf/message.h> etc.
  • link with -lprotobuf or -lprotobuf-lite

HTH

Peter

HTH
Peter

编辑:
使这一点更新更新。我尝试设置一个新的PC与当前版本的MinGW和protobuf 2.5.0,这些都是我遇到的问题:

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:


  1. 在开始菜单中没有MinGW Shell快捷方式。

    由于某些原因当前的MinGW安装无法安装。

    但是有一个 msys在< Mingw home> \ msys\1.0 中的.bat ,它会显示一个带有bash的控制台。

  1. There is no "MinGW Shell" shortcut in the start menu.
    For some reason current MinGW installations fail to install that.
    But there is a msys.bat in <Mingw home>\msys\1.0 which brings up a console with a bash. Create a shortcut to that batch file somewhere.

gcc在MSYS shell中不起作用。

我必须运行一个post-安装批处理文件并回答问题。这将设置在MSYS环境中安装mingw目录的fstab条目。

您需要运行< Mingw home> \ msys\1.0\postinstall\pi。 bat

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

我的Avira防病毒干扰了protobuf编译。

它抱怨生成的protoc.exe作为一个TR / Crypt.XPACK.Gen木马和阻止访问该文件,导致损坏的构建。

我得到错误消息,如 protoc:./。 libs / lt-protoc.c:233:FATAL:找不到原型。在尝试启动原型时。

我不得不禁用Avira实时扫描器和 make clean&&制作&& make install

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 like protoc:./.libs/lt-protoc.c:233: FATAL: couldn't find protoc. when trying to start protoc.
I had to disable the Avira realtime scanner and make clean && make && make install again

希望这有助于!

Peter

Hope this helps!
Peter

这篇关于如何使用MinGW在Windows中构建Google的protobuf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆