[Original] Network library libevent use in Windows environment

Source: Internet
Author: User

Libevent is an event-triggered network library, suitable for Windows, Linux, BSD and other platforms, internal use of Select, Epoll, Kqueue and other system invoke management event mechanism. Well-known distributed cache software memcached is also libevent based, and libevent in use can be cross-platform, and according to the Libevent official website published on the data statistics, it seems to have extraordinary performance.

1. Download and compile Libevent

Download the current libevent stable version of the LIBEVENT-2.0.21-STABLE.TAR.GZ installation package and extract it to a fixed directory. Open the command prompt terminal of Visual Studio, enter the Libevent-2.0.21-stable directory, and enter the following instructions to compile the Libevent code base:

NMAKE /F Makefile.nmake

2. Collect libevent related header files and library files

Libevent compilation is completed, the generated related static library files include three: Libevent.lib libevent_core.lib libevent_extras.lib, you can set up a Lib folder to store;

The related header files include three places: (1) libevent-2.0.12-stable\include\* (2) libevent-2.0.12-stable\win32-code\* (3) Libevent-2.0.12-stable\*.h

Copy these header files into a separate include folder for easy administration.

3. Specify Libevent's include and Lib folders in the VS project

There are two places designated: (1) When a new project is created, the Include folder path is given in the project's "Configuration Properties"-"C + +"-"general" and "Additional Include Directories", (2) directly at vs "Tools" and "Options"- The Include and Lib directory paths are given in the projects and solutions and VC + + directories.

In comparison, the first way I found out in the code, although the compilation will not be error, but can not automatically locate the header file and function location, the second way can clearly locate the Libevent header file and the location of the function.

4. Set the project run-Time library property

Select Multithreading (/MT) in the project's "Configuration Properties"--"C + +"-"code Generation" and "run-time Libraries".

5. Set up engineering dependencies and ignore function libraries

The "Additional dependencies" indicated in the project's "Configuration Properties" and "linker" and "input" include: Ws2_32.lib wsock32.lib libevent.lib libevent_core.lib Libevent_ Extras.lib

In "Ignore specific Libraries" includes: Libc.lib;msvcrt.lib;libcd.lib;libcmtd.lib;msvcrtd.lib

6. Test code

Try the test code for a bit:

View Code

[Original] Network library libevent use in Windows environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.