Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use VS2017 to compile libevent on windows platform

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how the windows platform compiles libevent using VS2017. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

A dependent library compilation

The first step is to compile the dependent library, where openssl needs to be compiled into libevent and compiled into the libevent_ openssl. lib library, zlib is only used by examples in the new version.

1) windows platform uses VS2017 to compile openssl source code

Refer to the previous article

Openssl compiles to C:\ Program Files (x86)\ OpenSSL directory by default, including the collection file, lib file and dll file. You need to configure this path later, or copy the compiled openssl library directly to the specified path.

2) use VS2017 to compile zlib source code

1) official website

Http://www.zlib.net/

2) compilation tool: VS2017 community version

Download address

Http://ffmpeg.club/tools_download.html

3) download the zlib1.2.11 source code

Download address

Http://ffmpeg.club/libevent.html

4) compilation steps

(1) enter the console (run CMD), or write a batch bat file

(2) run the vs compilation environment

In the open menu, there is a corresponding command line tool in VS2017. Copy the address.

Compile the 32-bit library version

C:\ Program Files (x86)\ Microsoft Visual Studio\ 2017\ Community\ VC\ Auxiliary\ Build\ vcvarsamd64_x86.bat

Compile the 64-bit library version

"C:\ Program Files (x86)\ Microsoft Visual Studio\ 2017\ Community\ VC\ Auxiliary\ Build\ vcvars64.bat"

After running, the following appears

(3) enter the directory of zlib source code

Cd zlib-1.2.11

(4) compile with nmake

Nmake-f win32/Makefile.msc-

The compiled dynamic library zdll.dll zdll.lib and static library zlib.lib are both in the zlib-1.2.11 root directory.

Preparation of libevent compilation environment

Operating system: windows 10 64 bit

Compilation tool: VS2017 community version

Download address

Http://ffmpeg.club/tools_download.html

Libevent 2.1.8 source code

Download address

Http://www.libevent.net/download

Compiling libevent source code

1) dependent on installation and compilation

Compilation tool: VS2017 community version

Download address

Http://ffmpeg.club/tools_download.html

After compiling and installing openssl, copy it to D:\ lib\ openssl path

Libevent_openssl.lib library is required. If you don't use this library, you can not compile openssl.

The compiled zlib is installed in D:\ libevent\ zlib-1.2.11\

The new version of libevent has been separated from zlib, but the example is useful for zlib. If you don't need this example, you can not compile zlib.

2) compilation steps

(1) enter the console (run CMD), or write a batch bat file

(2) run the vs compilation environment

In the open menu, there is a corresponding command line tool in VS2017. Copy the address.

Compile the 32-bit library version

C:\ Program Files (x86)\ Microsoft Visual Studio\ 2017\ Community\ VC\ Auxiliary\ Build\ vcvarsamd64_x86.bat

Compile the 64-bit library version

"C:\ Program Files (x86)\ Microsoft Visual Studio\ 2017\ Community\ VC\ Auxiliary\ Build\ vcvars64.bat"

(3) enter the directory of libevent source code

Cd libevent-master

(4) Clean up previous compilations

Nmake / f Makefile.nmake clean

(5) compile libevent

Nmake / f Makefile.nmake OPENSSL_DIR=D:\ lib\ openssl

OPENSSL_DIR is the path of openssl library. The path of zlib library needs to be established in the previous version, but not in the new version.

(6) compiling the library project and the sample project that contains libevent. The compiled sample project will cause problems because it uses zlib and the openssl version is relatively old.

3) problems in compilation

(1) openssl problem in the example

Problems that arise

Compilation error, showing ssleay32.lib and libeay32.lib libraries where openssl cannot be found

Reason

The old and new versions of openssl have different library names.

Solution

Open Makefile.nmake under the test directory

Find SSL_LIBS=..\ libevent_openssl.lib $(OPENSSL_DIR)\ lib\ libeay32.lib $(OPENSSL_DIR)\ lib\ ssleay32.lib gdi32.lib User32.lib

Change to SSL_LIBS=..\ libevent_openssl.lib $(OPENSSL_DIR)\ lib\ libssl.lib $(OPENSSL_DIR)\ lib\ libcrypto.lib gdi32.lib User32.lib

(2) zlib problem in the example

Problems that arise

The zlib sample is not compiled by default, and the zlib library and header file cannot be found after compilation

Solution

Set up the compile zlib sample before compiling libevent

Modify WIN32-Code\ nmake\ event2\ event-config.h

Add # define EVENTHAVE_LIBZ

The reason for the modification is determined in line 1382 of the sample code test\ regress_bufferevent.c

# ifdef EVENTHAVE_LIBZ

LEGACY (bufferevent_zlib, TT_ISOLATED)

# else

{"bufferevent_zlib", NULL, TT_SKIP, NULL, NULL}

# endif

Modify the compiled project of the zlib sample

Open Makefile.nmake under the test directory

Modify LIBS and set the zlib library file path

LIBS=..\ libevent.lib ws2_32.lib shell32.lib advapi32.lib D:\ libevent\ zlib-1.2.11\ zdll.lib

Modify CFLAGS add zlib header file path

CFLAGS=/I.. / I../WIN32-Code/ I../WIN32-Code/nmake / I../include / I../compat / DHAVE_CONFIG_H / DTINYTEST_LOCAL $(SSL_CFLAGS)-ID:\ libevent\ zlib-1.2.11

Thank you for reading! This is the end of this article on "how to compile libevent with VS2017 on the windows platform". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report