根据 http://zeromq.org/build:mingw 的说明,用MinGW来编译Zeri
最近折腾zeromq,,尝试用 MinGW 来编译了一下。
源码包下载地址:
根据 :mingw 的说明,用MinGW来编译 ZeroMQ 自然是没有问题的。但是业余测试一些简单的代码还是用静态库比较方便。怎奈何,默认的 configure 文件根本不支持用 MinGW 编译静态库。
“configure: error: Building static libraries is not supported under MinGW32”
具体可以查看
。
但是谁能限制不安分的程序猿呢。默认不支持不打紧,直接调用编译器来完成就是了。其他很多库也是这么撸出来的吧。
cd /path/to/zeromq-4.0.4
mkdir builds/mingw32
cp -vf builds/msvc/platform.hpp builds/mingw32
g++ -DZMQ_STATIC -DFD_SETSIZE=1024 -c ../../src/*.cpp
ar r libzmq.a *.o
可以参考:
遇到的一个严重问题是
..\..\src\windows.hpp:168:21: fatal error: Mstcpip.h: No such file or directory
#include
^
compilation terminated.
自己用的 MinGW 版本里没有 mstcpip.h 文件。放狗搜了下,在 cgminer 的编译说明里找到了解决方案。
https://github.com/Tydus/cgminer/blob/master/windows-build.txt
自行添加头文件 mstcpip.h:
struct tcp_keepalive
{
u_long onoff;
u_long keepalivetime;
u_long keepaliveinterval;
};
#ifndef USE_WS_PREFIX
#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR, 4)
#else
#define WS_SIO_KEEPALIVE_VALS _WSAIOW(WS_IOC_VENDOR, 4)
#endif
下面编译一下hello world吧。
#include
#include "zmq.h"
int main(int argc, char **argv)
{
int major, minor, patch;
zmq_version (&major, &minor, &patch);
printf ("Current 0MQ version is %d.%d.%d\n", major, minor, patch);
return 0;
}
gcc -c -o hello_zeromq.o hello_zeromq.c -g -I"../../inc" -I"../../../include/zeromq" -DZMQ_STATIC -I"../../inc" -I"../../../include/zeromq"
g++ -o hello_zeromq.exe hello_zeromq.o -L"../../lib" -L"../../../lib" -lzmq -lws2_32
执行结果:
./hello_zeromq.exe
Current 0MQ version is 4.0.4
第一步顺利完成,下面就需要进行修炼,编写需要的解决方案了。