libevent官网下载最新的libevent-2.1.8-stable.tar,地址:https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
直接用vs 命令行工具编译,我安装的是Microsoft Visual Studio Enterprise 2017,版本号是15.2(26430.16),使用x86 Native Tools Command Prompt for VS2017
切换到libevent目录下,执行nmake /f Makefile.nmake,报错:
test-changelist.c
cl /I.. /I../WIN32-Code /I../WIN32-Code/nmake /I../include /I../compat /DHAVE_CONFIG_H /DTINYTEST_LOCAL /Ox /W3 /wd4996 /nologo ..\libevent.lib ws2_32.lib shell32.lib advapi32.lib test-changelist.obj
NMAKE : fatal error U1073: don't know how to make 'print-winsock-errors.obj'
错误原因是找不到print-winsock-errors.c,其他的libevent版本是有这个文件的,于是拷贝过来,在执行顺利通过,产生三个libevent.lib libevent_core.lib libevent_extras.lib
print-winsock-errors.c
1 #include <winsock2.h>
2
3 #include <windows.h>
4
5
6
7 #include <stdlib.h>
8
9 #include <stdio.h>
10
11
12
13 #include "event2/event.h"
14
15 #include "event2/util.h"
16
17 #include "event2/thread.h"
18
19
20
21 #define E(x) printf (#x " -> \"%s\"\n", evutil_socket_error_to_string (x));
22
23
24
25 int main (int argc, char **argv)
26
27 {
28
29 int i, j;
30
31 const char *s1, *s2;
32
33
34
35 #ifdef EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED
36
37 evthread_use_windows_threads ();
38
39 #endif
40
41
42
43 s1 = evutil_socket_error_to_string (WSAEINTR);
44
45
46
47 for (i = 0; i < 3; i++) {
48
49 printf ("\niteration %d:\n\n", i);
50
51 E(WSAEINTR);
52
53 E(WSAEACCES);
54
55 E(WSAEFAULT);
56
57 E(WSAEINVAL);
58
59 E(WSAEMFILE);
60
61 E(WSAEWOULDBLOCK);
62
63 E(WSAEINPROGRESS);
64
65 E(WSAEALREADY);
66
67 E(WSAENOTSOCK);
68
69 E(WSAEDESTADDRREQ);
70
71 E(WSAEMSGSIZE);
72
73 E(WSAEPROTOTYPE);
74
75 E(WSAENOPROTOOPT);
76
77 E(WSAEPROTONOSUPPORT);
78
79 E(WSAESOCKTNOSUPPORT);
80
81 E(WSAEOPNOTSUPP);
82
83 E(WSAEPFNOSUPPORT);
84
85 E(WSAEAFNOSUPPORT);
86
87 E(WSAEADDRINUSE);
88
89 E(WSAEADDRNOTAVAIL);
90
91 E(WSAENETDOWN);
92
93 E(WSAENETUNREACH);
94
95 E(WSAENETRESET);
96
97 E(WSAECONNABORTED);
98
99 E(WSAECONNRESET);
100
101 E(WSAENOBUFS);
102
103 E(WSAEISCONN);
104
105 E(WSAENOTCONN);
106
107 E(WSAESHUTDOWN);
108
109 E(WSAETIMEDOUT);
110
111 E(WSAECONNREFUSED);
112
113 E(WSAEHOSTDOWN);
114
115 E(WSAEHOSTUNREACH);
116
117 E(WSAEPROCLIM);
118
119 E(WSASYSNOTREADY);
120
121 E(WSAVERNOTSUPPORTED);
122
123 E(WSANOTINITIALISED);
124
125 E(WSAEDISCON);
126
127 E(WSATYPE_NOT_FOUND);
128
129 E(WSAHOST_NOT_FOUND);
130
131 E(WSATRY_AGAIN);
132
133 E(WSANO_RECOVERY);
134
135 E(WSANO_DATA);
136
137 E(0xdeadbeef); /* test the case where no message is available */
138
139
140
141 /* fill up the hash table a bit to make sure it grows properly */
142
143 for (j = 0; j < 50; j++) {
144
145 int err;
146
147 evutil_secure_rng_get_bytes(&err, sizeof(err));
148
149 evutil_socket_error_to_string(err);
150
151 }
152
153 }
154
155
156
157 s2 = evutil_socket_error_to_string (WSAEINTR);
158
159 if (s1 != s2)
160
161 printf ("caching failed!\n");
162
163
164
165 libevent_global_shutdown ();
166
167
168
169 return EXIT_SUCCESS;
170
171 } 这个文件放置到libevent的test目录下