An environment
Official: http://libevent.org/
Version: Libevent-2.0.22-stable
Two compiled static libraries
1 decompression
Download the above to libevent-2.0.22-stable.tar.gz extract, get libevent-2.0.22-stable folder
2 adding a macro definition
Locate the following three files under the Libevent-2.0.22-stable folder:
Event_iocp.c
Evthread_win32.c
Listener.c
Open and add a macro definition at the beginning:
#define _WIN32_WINNT 0x0500
Because the function definitions in the <winbase.h> header file are used in event_iocp.c, such as InitializeCriticalSectionAndSpinCount,
The <windows.h> will contain <WINBASE.H>, and this function is defined in the <winbase.h> header file:
#if (_win32_winnt >= 0x0403)
Winbaseapi
BOOL WINAPI
InitializeCriticalSectionAndSpinCount (
__out lpcritical_section Lpcriticalsection,
__in DWORD dwSpinCount
);
Winbaseapi
DWORD
WINAPI
Setcriticalsectionspincount (
__inout lpcritical_section Lpcriticalsection,
__in DWORD dwSpinCount
);
#endif
So to define _WIN32_WINNT this macro, and the value is greater than 0x0403.
If you do not have this macro or do not meet the criteria, the compiler assumes that the function is undefined.
Wait for the link to look for it, so the symbol for the function assumes that an int is returned,
Instead of returning an int in the standard library file, the function symbol is not found at the link.
Note: macros must be defined before # include <windows.h>, otherwise it will not work.
3 compiling
Using the VS command-line tool, CD to libevent-2.0.22-stable directory, execute script makefile.nmake, command as follows:
nmake/f Makefile.nmake
This generates three static libraries:
Libevent_core.lib
Libevent_extras.lib
Libevent.lib
Three use example 1 new project
Create a new console "empty" project
2 Copy files
2.1 Create a Libevent folder under the project directory
2.2 Create a new Lib folder in Libevent and copy the above three lib files to this directory.
2.3 Create a new include folder in Libevent.
Copy the files and folders under Libevent-2.0.22-stable\include to this directory,
Copy the files and folders under Libevent-2.0.22-stable\win32-code to this directory,
2 files in the Event2 directory are merged together.
3 project configuration
VC + + Directory:
Include directory, add newly-created include directory
Library directory, add just the Lib directory;
C + +:
Code generation--Runtime library:
Debug mode: Multithreaded Debug (/MTD),
Release under Mode select: Multithreading (/MT)
Connector:
Additional dependencies, Input:
Ws2_32.lib
Wsock32.lib
Libevent.lib
Libevent_core.lib
Libevent_extras.lib
The other two libraries Ws2_32.lib and wsock32.lib are used to compile Windows network-related libraries.
4 test Code
4.1 Create a new MAIN.C file
4.2 Copy the code in the Time-test.c file from the Libevent-2.0.22-stable\sample directory into main
Libevent using steps in Windows