vs2019阅读Linux源码,vs2019 编译libevent并运行测试代码

首先在https://libevent.org/下载最新的Stable releases libevent-2.1.11-stable.tar.gz

编译前的准备

解压缩之后修改以下5个文件

在 event_iocp.c evthread_win32.c listener.c 中加入一个宏定义 #define _WIN32_WINNT 0x0500

修改 minheap-internal.h 其中有一个UINT32_MAX的宏定义不受支持 改成UINT_MAX

修改 Makefile.nmake 找到 CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo /Zi 务必加上最后一个选项方便调试

开始编译

打开 x86 Native Tools Command Prompt for VS 2019 切换到 libevent-2.1.11-stable 目录下执行 nmake /f Makefile.nmake

会生成3个lib文件

libevent_core.lib:All core event and buffer functionality. This library contains all the event_base, evbuffer, bufferevent, and utility functions.

libevent_extras.lib:This library defines protocol-specific functionality that you may or may not want for your application, including HTTP, DNS, and RPC.

libevent.lib:This library exists for historical reasons; it contains the contents of both libevent_core and libevent_extra. You shouldn’t use it; it may go away in a future version of Libevent.

不建议使用 libevent.lib

编译完成后使用

在目录下新生成了一个 WIN32-Code 把WIN32-Code\nmake目录下的所有内容复制到 include中 即可开始使用

在测试工程中添加 include 包含目录,链接依赖项中添加ws2_32.lib;wsock32.lib;libevent_core.lib

测试结果

e251eeb8bf6f08b166d10c312946ce87.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值