Linux under the compiled reference source of the Readme file, which is mainly recorded under Windows compilation.
I. Preparatory work
Go to the official website to download the latest stable release version libevent-2.0.22-stable
Website address: http://libevent.org/
Two. Compiling with VS2012
1. Unzip libevent to C:\Users\zhang\Desktop\libevent-2.0.22-stable
2. Open the VS2012 Developer Command Prompt tool, as shown in.
3. Enter the instruction to start compiling as shown in.
A netizen said that before compiling should be added "#define _WIN32_WINNT 0x0500" at the beginning of the following 3 files
Libevent-2.0.22-stable\event_iocp.c
Libevent-2.0.22-stable\evthread_win32.c
Libevent-2.0.21-stable\listener.c
But it doesn't explain why it was added, and I didn't add it, compile and use it.
Later still check the meaning of _win32_winnt, you can refer to: Modify Winver, _win32_winnt and _msc_ver
4. Compilation results
After the compilation succeeds, the following three library files are generated in the Libevent-2.0.22-stable directory.
Libevent.lib
Libevent_core.lib
Libevent_extras.lib
As for the functions of these three library files, you can refer to: libevent study: Libevent The characteristics and structure of the source code
5. Testing
The development tools I use are QT 5.5.1 VS2012.
Create a new console project, create a new "include" folder in the project root directory, and then do the following three steps.
(1) Copy the C:\Users\zhang\Desktop\libevent-2.0.22-stable\include\event2 folder to the project's "include" folder
(2) Copy the C:\Users\zhang\Desktop\libevent-2.0.22-stable\WIN32-Code\event2\event-config.h file to the project's "Include\event2" folder
(3) Copy the C:\Users\zhang\Desktop\libevent-2.0.22-stable\WIN32-Code\tree.h file to the project's "include" folder
Create a new "Lib" folder in the project root directory and copy the generated three library files to the folder.
The pro file looks like this:
[CPP]View PlainCopy
- QT + + Core
- QT-= GUI
- CONFIG + = c++11
- TARGET = Server
- CONFIG + = Console
- CONFIG-= App_bundle
- TEMPLATE = App
- SOURCES + = Main.cpp
- Includepath + = Include
- LIBS + = $ $PWD/lib/libevent.lib \
- $ $PWD/lib/libevent_core.lib \
- $ $PWD/lib/libevent_extras.lib \
- LIBS + =-lws2_32-ladvapi32
Windows socket communication needs to load ws2_32.lib, this everybody knows, as for why need Advapi32.lib, can refer to: LNK2019: unresolved external symbols [email protected]
Then copy the example C:\USERS\ZHANG\DESKTOP\LIBEVENT-2.0.22-STABLE\SAMPLE|H\ELLO-WORLD.C from Libevent to the project and compile it. It is important to note that there are two C2440 at compile time: "Initialize": Cannot convert from "void *" to "Event_base *" error, force a conversion.
This is an example of a simple server.
Three. Compiling with MinGW
1. Download the installation MSYS-1.0.11, rename the Fstab.sample file in C:\MinGW\msys\1.0\etc to Fstab after installation, and change the contents of Fstab to c:/qt/qt5.5.1/tools/mingw492 _32/MINGW, use the MinGW version of Qt, note that there are spaces between the path c:/qt/qt5.5.1/tools/mingw492_32 and/mingw
2. Open MSYS,CD to C:\Users\zhang\Desktop\libevent-2.0.22-stable directory,./configure, Make,make Install, after successful installation, generate a static library, as shown below.
C:\MINGW\MSYS\1.0\LOCAL\LIB\LIBEVENT.A,
C:\MINGW\MSYS\1.0\LOCAL\LIB\LIBEVENT_CORELIBEVENT.A,
C:\MinGW\msys\1.0\local\lib\libevent_extra.a
Copy the three library files to the project "Lib" directory.
Copy the header file shown in the project "Linclude" directory.
3. Testing
Or use that simple server example.
The pro file looks like this:
[CPP]View PlainCopy
- QT + + Core
- QT-= GUI
- CONFIG + = c++11
- TARGET = Server
- CONFIG + = Console
- CONFIG-= App_bundle
- TEMPLATE = App
- SOURCES + = Main.cpp
- Includepath + = Include
- LIBS + = $ $PWD/lib/libevent.a \
- $ $PWD/lib/libevent_core.a \
- $ $PWD/lib/libevent_extra.a \
- LIBS + =-lws2_32-ladvapi32
- Defines + = WIN32
Note that compared to the "Use vs ' 2012 compilation" Pro file, the last defines + = WIN32, or compile the project will be error.
Of course, the QT version used for compiling the project is QT 5.5.1 MingW.
http://blog.csdn.net/caoshangpa/article/details/52838156
Libevent Learning II: Windows7 (Win7) under compilation libevent