0%

Windows下编译一些开源基础库

#Windows下 Perl 运行环境

Perl脚本语言在windows下有三个实现可以用,一般网上会建议安装ActivePerl的免费社区版本,我在winxp下安装不成功选了另一个DWIN Perl,还有一个StrawberryPerl没有试过.

  • 默认安装在C:\Dwimperl,完成之后把它添加到环境变量,或者运行它自带的脚本C:\Dwimperl\update_env.pl.bat.

Cygwin,MinGW,MSYS

-windows下一些GNU工具套装介绍,摘自网络.

  1. MinGWwindows版本的gcc集合,不需要依赖中间层.
  2. MSYS 是小型的linux的环境的模拟,可以与MinGW结合来模拟linux环境下使用MinGWgcc,但是好久都不更新了,现在网有一个MSYS2,但是这两个环境在winxp下安装不成功,之前是可以安装msys.可以进入这里:谁在使用msys2
  3. Cygwin是功能强大的linux环境,由于有cygwin1.dll实现了底层的windows apilinux api的转化.所以在Cygwin里开发就相当于在linux上开发,对于开发人员来说就相当于调用linux类型的api,所以这样开发的程序也可以直接移植到linux上.但是如果这样的程序要在windows上执行的话,运行时必须要cygwin1.dll支持.

安装Qt MinGW版本的 IDE

  • 本人还是喜欢使用Qt来现在界面程,惟一缺点就是生成静态库的执行程序有比较大,Qtwin下面有两个版本,GCC,MSVC.我下面要做的编译基础库都是基于QT安装自带的MinGW GCC,这样在QT中再调用这些库就不会出现一些奇奇怪怪的问题了.

Zlib

##MinGW编译

  • 下截zlib最新版本,解压到出来.打开一个命令行窗口,执行Qt MinGW环境脚本C:\WINDOWS\system32\cmd.exe /A /Q /K C:\Qt\Qt5.7.1\5.7\mingw53_32\bin\qtenv2.bat,一般装完Qt会有指向这个脚本的快捷方式,点击运行即可.
1
2
3
4
5
6
7
8
9
10
11
12

D:\zlib-1.2.11\zlib-1.2.11>mingw32-make -f win32/Makefile.gcc
gcc -O3 -Wall -c -o adler32.o adler32.c
gcc -O3 -Wall -c -o compress.o compress.c
gcc -O3 -Wall -c -o crc32.o crc32.c

...

strip example_d.exe
gcc -o minigzip_d.exe minigzip.o libz.dll.a
strip minigzip_d.exe

按上面编译成功后,会当前目录下生成zlib1.dll,libz.dll.a ,libz等库文件,把这些库文件与头文件复到一个目录,包含并链接它们就可以了.

MSVC编译

x86 32bit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

D:\SourceBuild\zlib-1.2.11>vcvarsall.bat
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
D:\SourceBuild\zlib-1.2.11>nmake /f win32/Makefile.msc

Microsoft (R) 程序维护实用工具 10.00.30319.01 版
版权所有(C) Microsoft Corporation.保留所有权利.

cl -c -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -nologo -MD
-W3 -O2 -Oy- -Zi -Fd"zlib" .\adler32.c
adler32.c
cl -c -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -nologo -MD
-W3 -O2 -Oy- -Zi -Fd"zlib" .\compress.c
compress.c

...

fest -outputresource:example_d.exe;1
link -nologo -debug -incremental:no -opt:ref -out:minigzip_d.exe minigzi
p.obj zdll.lib
if exist minigzip_d.exe.manifest mt -nologo -manifest minigzip_d.exe.ma
nifest -outputresource:minigzip_d.exe;1

编译完成后会生成zlib.lib,zlib1.dll等一些文件.

x86_amd64

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
D:\SourceBuild\zlib-1.2.11>vcvarsx86_amd64.bat
Setting environment for using Microsoft Visual Studio 2010 x64 cross tools.


D:\SourceBuild\zlib-1.2.11>nmake /f win32/Makefile.msc

Microsoft (R) 程序维护实用工具 10.00.30319.01 版
版权所有(C) Microsoft Corporation.保留所有权利.

cl -c -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -nologo -MD
-W3 -O2 -Oy- -Zi -Fd"zlib" .\adler32.c
adler32.c
cl -c -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -nologo -MD
-W3 -O2 -Oy- -Zi -Fd"zlib" .\compress.c
compress.c

...

fest -outputresource:example_d.exe;1
link -nologo -debug -incremental:no -opt:ref -out:minigzip_d.exe minigzi
p.obj zdll.lib
if exist minigzip_d.exe.manifest mt -nologo -manifest minigzip_d.exe.ma
nifest -outputresource:minigzip_d.exe;1

OpenSSL

  • 下载openssl-1.1.0e,解压出来,仔细阅读里面NOTES.WIN,INSTALL这两个文本文档,里面有详细的编译安装说明.里面调用nmakenative 编译的,要确保机器安装了Visual Stduio开发环境,winxp最高只能安装vs2010.这里没有找到使用MinGW编译的方法只能使用nmake来编译,开发启zlib支持就只能使用zlibMSVC的编译版本.
  • 编译前先初始化MSVC的环境变量,有分x86x86_amd64,确保C:\Program Files\Microsoft Visual Studio 10.0\VC加入用户的PATH变量里面.打开一个新命令行窗口执行:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
D:\SourceBuild\openssl-1.1.0e>vcvarsall.bat
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

D:\SourceBuild\openssl-1.1.0e> perl Configure VC-WIN32
Configuring OpenSSL version 1.1.0e (0x1010005fL)
no-asan [default] OPENSSL_NO_ASAN
no-crypto-mdebug [default] OPENSSL_NO_CRYPTO_MDEBUG
no-crypto-mdebug-backtrace [default] OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
no-ec_nistp_64_gcc_128 [default] OPENSSL_NO_EC_NISTP_64_GCC_128
no-egd [default] OPENSSL_NO_EGD
no-fuzz-afl [default] OPENSSL_NO_FUZZ_AFL
no-fuzz-libfuzzer [default] OPENSSL_NO_FUZZ_LIBFUZZER
no-heartbeats [default] OPENSSL_NO_HEARTBEATS
no-md2 [default] OPENSSL_NO_MD2 (skip dir)
no-msan [default] OPENSSL_NO_MSAN
no-rc5 [default] OPENSSL_NO_RC5 (skip dir)
no-sctp [default] OPENSSL_NO_SCTP
no-ssl-trace [default] OPENSSL_NO_SSL_TRACE
no-ssl3 [default] OPENSSL_NO_SSL3
no-ssl3-method [default] OPENSSL_NO_SSL3_METHOD
no-ubsan [default] OPENSSL_NO_UBSAN
no-unit-test [default] OPENSSL_NO_UNIT_TEST
no-weak-ssl-ciphers [default] OPENSSL_NO_WEAK_SSL_CIPHERS
no-zlib [default]
no-zlib-dynamic [default]
Configuring for VC-WIN32
CC =cl
CFLAG =-W3 -wd4090 -Gs0 -GF -Gy -nologo -DOPENSSL_SYS_WIN32 -DWIN32_LEAN
_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -DUNICODE -D_UNICODE /MD /O2
[...]

D:\SourceBuild\openssl-1.1.0e>nmake
[...]

D:\SourceBuild\openssl-1.1.0e>nmake test
[...]

C-ares

  • 下载C-ares-1.12,查看了它自带README,通过命令行使用nmake安装不成功,通过它的vc目录下的VC工程,要用vs2010IDE打开就可以编译在成功.生成了cares.lib,cares.dll.

Curl

  • 下载curl-7.53.1,解压出来,仔细阅读它的文档.winbuild/BUILD.WINDOWS.txt文档详细说明了如何编译安装.

  • 根据文档指示,如果依赖一些其它库要在它的同级目录新建如下结构的目录结构

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    If you wish to support zlib, openssl, c-ares, ssh2, you will have to download
    them separately and copy them to the deps directory as shown below:

    somedirectory
    |_curl-src
    | |_winbuild
    |
    |_deps
    |_ lib
    |_ include
    |_ bin
  • 目录结构如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
D:\SourceBuild\deps>tree /?
以图形显示驱动器或路径的文件夹结构.

TREE [drive:][path] [/F] [/A]

/F 显示每个文件夹中文件的名称.
/A 使用 ASCII 字符,而不使用扩展字符.


D:\SourceBuild\deps>tree /F
卷 新加卷 的文件夹 PATH 列表
卷序列号码为 0006EE44 E462:E6DB
D:.
├─include
│ │ ares.h
│ │ ares_build.h
│ │ ares_rules.h
│ │ ares_version.h
│ │ zconf.h
│ │ zlib.h
│ │
│ ├─internal
│ │ bio.h
│ │ comp.h
│ │ conf.h
│ │ constant_time_locl.h
│ │ dane.h
│ │ dso.h
│ │ err.h
│ │ numbers.h
│ │ o_dir.h
│ │ o_str.h
│ │ thread_once.h
│ │
│ └─openssl
│ aes.h
│ asn1.h
│ asn1t.h
│ asn1_mac.h
│ async.h
│ [...]
│ x509v3.h
│ x509_vfy.h
│ __DECC_INCLUDE_EPILOGUE.H
│ __DECC_INCLUDE_PROLOGUE.H

└─lib
cares.dll
cares.lib
libcrypto-1_1.dll
libcrypto.lib
libssl-1_1.dll
libssl.lib
zdll.lib
zlib.h
zlib.lib
zlib1.dll
  • 因为这个版本的CURL依赖openssl时,会连接libeay32.lib,ssleay32.lib.这里要在脚本文件\winbuild\MakefileBuild.vc里把它改成libssl.lib,libcrypto.lib.
1
2
3
D:\SourceBuild\curl-7.53.1\winbuild>nmake /f Makefile.vc mode=dll vc=10 with_ssl
=dll with_cares=dll with_zlib=dll machine=x86

  • 如果不出错就会产生几个新的文件夹如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
D:\SourceBuild\curl-7.53.1\builds>tree
卷 新加卷 的文件夹 PATH 列表
卷序列号码为 0006EE44 E462:E6DB
D:.
├─libcurl-vc10-x86-release-dll-ssl-dll-cares-dll-zlib-dll-ipv6-sspi
│ ├─bin
│ ├─include
│ │ └─curl
│ └─lib
├─libcurl-vc10-x86-release-dll-ssl-dll-cares-dll-zlib-dll-ipv6-sspi-obj-curl
└─libcurl-vc10-x86-release-dll-ssl-dll-cares-dll-zlib-dll-ipv6-sspi-obj-lib
├─vauth
└─vtls

###MinGW下编译CURL

1
2
3
4
D:\SourceBuild\curl-7.53.1>mkdir mingwbuild
D:\SourceBuild\curl-7.53.1>cd mingwbuild
D:\SourceBuild\curl-7.53.1\mingwbuild>cmake -G "MinGW Makefiles" ../
D:\SourceBuild\curl-7.53.1\mingwbuild>mingw32-make
  • 会在当前目录下生成库文件与一些测试程序.

#MXE环境下交叉编译一些库

1
2
3
4
5
6
7
8
9
10
$cd mxe
mxe$ make MXE_TARGETS="i686-w64-mingw32.shared" curl libwebsockets

$ cd ~/mxe/download_src/c-ares-1.12.0/build$
$ export CROSS_COMPILER=i686-w64-mingw32.shared-
$ ../configure --prefix=/path/mxe/usr/i686-w64-mingw32.shared --host=i686-w64-mingw32
$ make && make install
$ ls /path/mxe/usr/i686-w64-mingw32.shared/lib/libcares.*
/path/mxe/usr/i686-w64-mingw32.shared/lib/libcares.dll.a /path/mxe/usr/i686-w64-mingw32.shared/lib/libcares.la

mosquitto

  • 下载Mosquitto-1.4.11,解压出来,看了一下它的readme-windows.txtwinxp下编译安装不成功,不管是MSVC还是MinGW.我根据错误提示做了一些源代码的修改,使用Qt MinGW还有MXE环境下编译成功了.修改如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
$ diff -r mosquitto-1.4.11 mosquitto-1.4.11-lcy-changed
Only in mosquitto-1.4.11-lcy-changed: build
diff -r mosquitto-1.4.11/config.mk mosquitto-1.4.11-lcy-changed/config.mk
68c68
< WITH_WEBSOCKETS:=no
---
> WITH_WEBSOCKETS:=yes
diff -r mosquitto-1.4.11/lib/CMakeLists.txt mosquitto-1.4.11-lcy-changed/lib/CMakeLists.txt
7,8c7,12
< set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x86\\pthreadVC2.lib)
< set (PTHREAD_INCLUDE_DIR C:\\pthreads\\Pre-built.2\\include)
---
> if (MINGW)
> set (PTHREAD_LIBRARIES -lpthread)
> else ( MINGW)
> set (PTHREAD_LIBRARIES C:\\pthreads\\Pre-built.2\\lib\\x86\\pthreadVC2.lib)
> set (PTHREAD_INCLUDE_DIR C:\\pthreads\\Pre-built.2\\include)
> endif (MINGW)
diff -r mosquitto-1.4.11/lib/mosquitto_internal.h mosquitto-1.4.11-lcy-changed/lib/mosquitto_internal.h
20a21
> #include <stdint.h>
diff -r mosquitto-1.4.11/lib/net_mosq.c mosquitto-1.4.11-lcy-changed/lib/net_mosq.c
29a30
> #define AI_ADDRCONFIG 0x400
diff -r mosquitto-1.4.11/lib/time_mosq.c mosquitto-1.4.11-lcy-changed/lib/time_mosq.c
45,47c45,48
< if(vi.dwMajorVersion > 5){
< tick64 = true;
< }
---
> if(vi.dwMajorVersion > 5 )
> {
> tick64 = true;
> }
56c57
< return GetTickCount64()/1000;
---
> return GetTickCount()/1000;
diff -r mosquitto-1.4.11/lib/tls_mosq.c mosquitto-1.4.11-lcy-changed/lib/tls_mosq.c
21a22
> # include <windows.h>
118,119c119,128
< ipv6_ok = InetPton(AF_INET6, hostname, &ipv6_addr);
< ipv4_ok = InetPton(AF_INET, hostname, &ipv4_addr);
---
> typedef INT (WSAAPI *ptrInetPton)( INT Family, PCTSTR pszAddrString, PVOID pAddrBuf);
> HMODULE h = LoadLibrary(L"ws2_32.dll");
> ptrInetPton func = (ptrInetPton)GetProcAddress(h,"InetPtonW");
>
> ipv6_ok = func(AF_INET6, hostname, &ipv6_addr);
> ipv4_ok = func(AF_INET, hostname, &ipv4_addr);
> FreeLibrary(h); h = NULL;
>
> //ipv6_ok = InetPton(AF_INET6, hostname, &ipv6_addr);
> //ipv4_ok = InetPton(AF_INET, hostname, &ipv4_addr);
diff -r mosquitto-1.4.11/src/conf.c mosquitto-1.4.11-lcy-changed/src/conf.c
33a34
> #define AI_ADDRCONFIG 0x400
diff -r mosquitto-1.4.11/src/loop.c mosquitto-1.4.11-lcy-changed/src/loop.c
27a28,107
> #include <windows.h>
> #if (_WIN32_WINNT < 0x0600)
>
> #define POLLIN 0x0001
> #define POLLPRI 0x0002
> #define POLLOUT 0x0004
> #define POLLERR 0x0008
> #define POLLHUP 0x0010
> #define POLLNVAL 0x0020
>
> #ifdef FD_SETSIZE
> #undef FD_SETSIZE
> #endif
>
> #define FD_SETSIZE 1000
>
> struct pollfd {
> SOCKET fd;
> short events;
> short revents;
> };
>
>
> int mingw_poll(struct pollfd *fds, unsigned int nfds, int timo)
> {
> struct timeval timeout, *toptr;
> fd_set ifds, ofds, efds, *ip, *op;
> int i, rc;
>
> /* Set up the file-descriptor sets in ifds, ofds and efds. */
> FD_ZERO(&ifds);
> FD_ZERO(&ofds);
> FD_ZERO(&efds);
> for (i = 0, op = ip = 0; i < nfds; ++i) {
> fds[i].revents = 0;
> if(fds[i].events & (POLLIN|POLLPRI)) {
> ip = &ifds;
> FD_SET(fds[i].fd, ip);
> }
> if(fds[i].events & POLLOUT) {
> op = &ofds;
> FD_SET(fds[i].fd, op);
> }
> FD_SET(fds[i].fd, &efds);
> }
>
> /* Set up the timeval structure for the timeout parameter */
> if(timo < 0) {
> toptr = 0;
> } else {
> toptr = &timeout;
> timeout.tv_sec = timo / 1000;
> timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000;
> }
>
> //kWarning()<<QString("Entering select() sec=%1 usec=%2 ip=%3 op=%4").arg(timeout.tv_sec).arg(timeout.tv_usec).arg((long)ip).arg((long)op);
>
> rc = select(0, ip, op, &efds, toptr);
>
> //kWarning()<<"Exiting select rc="<<rc;
>
> if(rc <= 0)
> return rc;
>
> if(rc > 0) {
> for (i = 0; i < nfds; ++i) {
> int fd = fds[i].fd;
> if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
> fds[i].revents |= POLLIN;
> if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
> fds[i].revents |= POLLOUT;
> if(FD_ISSET(fd, &efds))
> /* Some error was detected ... should be some way to know. */
> fds[i].revents |= POLLHUP;
> //kWarning()<<QString("%1 %2 %3 revent = %4").arg(FD_ISSET(fd, &ifds)).arg(FD_ISSET(fd, &ofds)).arg(FD_ISSET(fd, &efds)).arg(fds[i].revents);
> }
> }
> return rc;
> }
> #endif
354c434,435
< fdcount = WSAPoll(pollfds, pollfd_index, 100);
---
> //fdcount = WSAPoll(pollfds, pollfd_index, 100);
> fdcount = mingw_poll(pollfds, pollfd_index, 100);
diff -r mosquitto-1.4.11/src/net.c mosquitto-1.4.11-lcy-changed/src/net.c
26a27
> #include <windows.h>
516a518,523
> #ifdef WIN32
>
> typedef PCTSTR (WSAAPI *ptrInetNtop)( INT Family, PVOID pAddr, PTSTR pStringBuf, size_t StringBufSize);
> HMODULE h = LoadLibrary(L"ws2_32.dll");
> ptrInetNtop func = (ptrInetNtop)GetProcAddress(h,"InetNtop");
> #endif
520a528,531
> #ifdef WIN32
> if(func(AF_INET, &((struct sockaddr_in *)&addr)->sin_addr.s_addr, buf, len)){
> return 0;
> #else
522a534
> #endif
524a537,540
> #ifdef WIN32
> if(func(AF_INET6, &((struct sockaddr_in6 *)&addr)->sin6_addr.s6_addr, buf, len)){
> return 0;
> #else
526a543
> #endif
529a547,549
> #ifdef WIN32
> FreeLibrary(h);
  • MXE编译参数如下,要先安装OPENSSL
1
cmake -DCMAKE_SHARED_LIBRARY_LINK_C_FLAGS="" -DCMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS="" -DWIN32=ON -DMINGW=ON -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=i686-w64-mingw32.shared-gcc  -DOPENSSL_ROOT_DIR=/path/usr/i686-w64-mingw32.shared ..
  • Qt MinGW编译
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

D:\SourceBuild\mosquitto-1.4.11-lcy-changed> mkdir build
D:\SourceBuild\mosquitto-1.4.11-lcy-changed> cd build
D:\SourceBuild\mosquitto-1.4.11-lcy-changed\build>cmake -G "MinGW Makefiles" ..
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/Qt/Qt5.7.1/Tools/mingw530_32/bin/gcc.exe
-- Check for working C compiler: C:/Qt/Qt5.7.1/Tools/mingw530_32/bin/gcc.exe --
works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Qt/Qt5.7.1/Tools/mingw530_32/bin/g++.exe
-- Check for working CXX compiler: C:/Qt/Qt5.7.1/Tools/mingw530_32/bin/g++.exe -
- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: C:/Dwimperl/c/lib/libssleay32.a (found version "1.0.0d")
CMake Warning at lib/CMakeLists.txt:73 (message):
c-ares library not found.


-- Looking for getaddrinfo_a in anl
-- Looking for getaddrinfo_a in anl - not found
-- Configuring done
-- Generating done
-- Build files have been written to: D:/SourceBuild/mosquitto-1.4.11-lcy-changed
/build

D:\SourceBuild\mosquitto-1.4.11-lcy-changed\build> mingw32-make

[...]

MinGW编译rabbitmq-c

  • rabbitmq-cRabbitMQ的一个C语言客户实现,它的代码可以通过使用MinGW交叉编译到Windows上使用.
1
2
3
4
5
~$ git clone https://github.com/alanxz/rabbitmq-c
~$ cd rabbitmq-c && mkdir build
~$ cd build
~$ cmake -DWIN32=ON -DMINGW=ON -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32.static-gcc -DOPENSSL_ROOT_DIR=/fullpath/usr/x86_64-w64-mingw32.static ..

错误处理

  • 如果出现下面错误,需要在CMakeLists.txt加下面的参数.

CMAKE出错

1
2
3
4
-- Check if compiler accepts -pthread
CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
THREADS_PTHREAD_ARG (advanced)

  • 加入下面三行到 CMakeLists.txt
1
2
3
SET( THREADS_PTHREAD_ARG
"PLEASE_FILL_OUT-FAILED_TO_RUN"
CACHE STRING "Result from TRY_RUN" FORCE)

编译tests出错

1
2
3
4
5
6
rabbitmq-c/tests/test_basic.c:34:22: fatal error: WinSock2.h: No such file or directory
compilation terminated.
tests/CMakeFiles/test_basic.dir/build.make:63: recipe for target 'tests/CMakeFiles/test_basic.dir/test_basic.c.obj' failed
make[2]: *** [tests/CMakeFiles/test_basic.dir/test_basic.c.obj] Error 1
CMakeFiles/Makefile2:406: recipe for target 'tests/CMakeFiles/test_basic.dir/all' failed
make[1]: *** [tests/CMakeFiles/test_basic.dir/all] Error 2
  • 1, 可以在CMAKE时不编译tests.
  • 2, 把WinSock2.h改成winsock2.h试试.

总结

  • 上面提到这些库都是可以通过MSVC或者MinGW可以编译出来,一整套的编译环境加上一大堆的依赖库,还要应对一些编译器带来的错误,一般是不会像上面这样一个一个的去编译,更好的方法是使用MXE去编译上面这些库,但是依赖的动态库文件会比较多.

谢谢支持