nmake、cmake、Visual Studio编译libevent

开篇提示1:本文为本人原创,“第一个”讲解cmake编译libevent库。
开篇提示2:本文欢迎转载,但必须注明本文出处,例如:
“该文引用自 CruiseYoung的: nmake、cmake、Visual Studio编译libevent 
http://blog.csdn.net/fksec/article/details/25989419” 
否则说明阁下愿意支付以100元人民币每字计的稿费,敬请留意。

:本文基于Win x64位平台来讲解,x86基本相同

1 前期准备

1.1 OpenSSL编译: http://blog.csdn.net/fksec/article/details/25969257
1.2 zlib编译: http://blog.csdn.net/fksec/article/details/25906419
1.3 libevent官网: http://libevent.org/
      代码托管地址: https://github.com/libevent/libevent
1.4 阅读
libevent\README.md
libevent\Makefile.am
libevent\Makefile.nmake
libevent\test\Makefile.nmake
libevent\CMakeLists.txt
1.5 zlib库,在libevent的test库中用到;OpenSSL库是为libevent增加SSL功能;

2 nmake编译准备

2.1 解压“libevent-2.1.4-alpha.tar.gz”到当前文件夹,用以下命令切换到“libevent”目录: 
cd /d E:\Projects\compile\libevent
2.2 复制Make文件(x64位 Release编译)
copy Makefile.nmake Makefile.nmake.x64.release
copy test\Makefile.nmake test\Makefile.nmake.x64.release
2.3 修改“Makefile.nmake.x64.release”和“test\Makefile.nmake.x64.release”
在CFLAGS定义处增加:
CFLAGS=$(CFLAGS) /D_WIN32_WINNT=0x0501
CFLAGS=$(CFLAGS) /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE
CFLAGS=$(CFLAGS) /Zi
注:在“最新的2.1.0”以上的版本中好像可以不用加第一句了,但加上也没有关系;
2.4、修改“clean”标签
2.4.1 在“Makefile.nmake.x64.release”文件“clean”标签的“del $(STATIC_LIBS)”一句后增加:
del *.ilk
del *.pdb
2.4.2 在“test\Makefile.nmake.x64.release”文件“clean”标签的“-del $(PROGRAMS)”一句后增加:
-del *.ilk
-del *.pdb
-del regress.gen.h
-del regress.gen.c
2.5 x64位编程,需要增加内容,x86编译不需要
2.5.1 在“Makefile.nmake.x64.release”文件中“LIBFLAGS”定义处增加
LIBFLAGS=$(LIBFLAGS) /MACHINE:X64
2.5.2 在“test\Makefile.nmake.x64.release”文件中增加
LIBFLAGS=/nologo
LIBFLAGS=$(LIBFLAGS) /MACHINE:X64
2.6 在引用带有“zlib”库的“OpenSSL”时,在“test\Makefile.nmake.x64.release”文件作如下修改:
在CFLAGS定义之前添加:
!IFDEF ZLIB_DIR
ZLIB_CFLAGS=/I$(ZLIB_DIR)\include /DEVENT__HAVE_ZLIB
ZLIB_LIBS=$(ZLIB_DIR)\lib\zlib.lib
!ELSE
ZLIB_CFLAGS=
ZLIB_LIBS=
!ENDIF
在CFLAGS定义之后添加:
CFLAGS=$(CFLAGS) $(ZLIB_CFLAGS)
将以下语句:
regress.exe: $(REGRESS_OBJS)
	$(CC) $(CFLAGS) $(LIBS) $(SSL_LIBS) $(REGRESS_OBJS)
更改为:
regress.exe: $(REGRESS_OBJS)
	$(CC) $(CFLAGS) $(LIBS) $(SSL_LIBS) $(REGRESS_OBJS) $(ZLIB_LIBS)
2.7 复制Make文件(x64位 Debug编译)
copy Makefile.nmake.x64.release Makefile.nmake.x64.debug
copy test\Makefile.nmake.x64.release test\Makefile.nmake.x64.debug
将CFLAGS定义处的“/Ox”改为“/Od”
在CFLAGS定义处增加:
CFLAGS=$(CFLAGS) -D_DEBUG
2.8 修改“test”对应编译文件名
将“Makefile.nmake.x64.release”文件中所有“Makefile.nmake”改为“Makefile.nmake.x64.release”
将“Makefile.nmake.x64.debug”文件中所有“Makefile.nmake”改为“Makefile.nmake.x64.debug”
2.9 nmake编译模式,目前只能编译出静态库

3 nmake Debug编译

set OPENSSL_DIR=D:\comm\openssl\debug_x64_static
set ZLIB_DIR=D:\comm\zlib\debug_x64

nmake -f Makefile.nmake.x64.debug static_libs
nmake -f Makefile.nmake.x64.debug tests

mkdir D:\comm
mkdir D:\comm\libevent
mkdir D:\comm\libevent\debug_x64_static
mkdir D:\comm\libevent\debug_x64_static\include

xcopy /E /H /R .\include\* D:\comm\libevent\debug_x64_static\include  
xcopy /E /H /R .\WIN32-Code\nmake\* D:\comm\libevent\debug_x64_static\include  
  
xcopy /E /H /R .\compat\* D:\comm\libevent\debug_x64_static\include  
xcopy /H /R .\WIN32-Code\*.h D:\comm\libevent\debug_x64_static\include  
xcopy /H /R .\*.h D:\comm\libevent\debug_x64_static\include

mkdir D:\comm\libevent\debug_x64_static\lib
copy /Y libevent.lib D:\comm\libevent\debug_x64_static\lib
copy /Y libevent_core.lib D:\comm\libevent\debug_x64_static\lib
copy /Y libevent_extras.lib D:\comm\libevent\debug_x64_static\lib
copy /Y libevent_openssl.lib D:\comm\libevent\debug_x64_static\lib

nmake -f Makefile.nmake.x64.debug clean
或者:
nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static -f Makefile.nmake.x64.debug static_libs
nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static -f Makefile.nmake.x64.debug tests

nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static ZLIB_DIR=D:\comm\zlib\debug_x64 -f Makefile.nmake.x64.debug static_libs
nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static ZLIB_DIR=D:\comm\zlib\debug_x64 -f Makefile.nmake.x64.debug tests

mkdir D:\comm
mkdir D:\comm\libevent
mkdir D:\comm\libevent\debug_x64_static
mkdir D:\comm\libevent\debug_x64_static\include

xcopy /E /H /R .\include\* D:\comm\libevent\debug_x64_static\include
xcopy /E /H /R .\WIN32-Code\nmake\* D:\comm\libevent\debug_x64_static\include

xcopy /E /H /R .\compat\* D:\comm\libevent\debug_x64_static\include
xcopy /H /R .\WIN32-Code\*.h D:\comm\libevent\debug_x64_static\include
xcopy /H /R .\*.h D:\comm\libevent\debug_x64_static\include

mkdir D:\comm\libevent\debug_x64_static\lib
copy /Y libevent.lib D:\comm\libevent\debug_x64_static\lib
copy /Y libevent_core.lib D:\comm\libevent\debug_x64_static\lib
copy /Y libevent_extras.lib D:\comm\libevent\debug_x64_static\lib
copy /Y libevent_openssl.lib D:\comm\libevent\debug_x64_static\lib

nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static -f Makefile.nmake.x64.debug clean

nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static ZLIB_DIR=D:\comm\zlib\debug_x64 -f Makefile.nmake.x64.debug clean
注:如果要编译静态库和测试库,可用以下任意一条命令:
nmake -f Makefile.nmake.x64.debug
nmake -f Makefile.nmake.x64.debug all

nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static -f Makefile.nmake.x64.debug
nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static -f Makefile.nmake.x64.debug all

nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static ZLIB_DIR=D:\comm\zlib\debug_x64 -f Makefile.nmake.x64.debug
nmake OPENSSL_DIR=D:\comm\openssl\debug_x64_static ZLIB_DIR=D:\comm\zlib\debug_x64 -f Makefile.nmake.x64.debug all

4 nmake Release编译

set OPENSSL_DIR=D:\comm\openssl\release_x64_static
set ZLIB_DIR=D:\comm\zlib\release_x64

nmake -f Makefile.nmake.x64.release static_libs
nmake -f Makefile.nmake.x64.release tests

mkdir D:\comm
mkdir D:\comm\libevent
mkdir D:\comm\libevent\release_x64_static
mkdir D:\comm\libevent\release_x64_static\include

xcopy /E /H /R .\include\* D:\comm\libevent\release_x64_static\include
xcopy /E /H /R .\WIN32-Code\nmake\* D:\comm\libevent\release_x64_static\include

xcopy /E /H /R .\compat\* D:\comm\libevent\release_x64_static\include
xcopy /H /R .\WIN32-Code\*.h D:\comm\libevent\release_x64_static\include
xcopy /H /R .\*.h D:\comm\libevent\release_x64_static\include

mkdir D:\comm\libevent\release_x64_static\lib
copy /Y libevent.lib D:\comm\libevent\release_x64_static\lib
copy /Y libevent_core.lib D:\comm\libevent\release_x64_static\lib
copy /Y libevent_extras.lib D:\comm\libevent\release_x64_static\lib
copy /Y libevent_openssl.lib D:\comm\libevent\release_x64_static\lib

nmake -f Makefile.nmake.x64.release clean
或者:
nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static -f Makefile.nmake.x64.release static_libs
nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static -f Makefile.nmake.x64.release tests

nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static ZLIB_DIR=D:\comm\zlib\release_x64 -f Makefile.nmake.x64.release static_libs
nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static ZLIB_DIR=D:\comm\zlib\release_x64 -f Makefile.nmake.x64.release tests

mkdir D:\comm
mkdir D:\comm\libevent
mkdir D:\comm\libevent\release_x64_static
mkdir D:\comm\libevent\release_x64_static\include
xcopy /E /H /R .\include\* D:\comm\libevent\release_x64_static\include
xcopy /E /H /R .\WIN32-Code\nmake\* D:\comm\libevent\release_x64_static\include

xcopy /E /H /R .\compat\* D:\comm\libevent\release_x64_static\include
xcopy /H /R .\WIN32-Code\*.h D:\comm\libevent\release_x64_static\include
xcopy /H /R .\*.h D:\comm\libevent\release_x64_static\include

mkdir D:\comm\libevent\release_x64_static\lib
copy /Y libevent.lib D:\comm\libevent\release_x64_static\lib
copy /Y libevent_core.lib D:\comm\libevent\release_x64_static\lib
copy /Y libevent_extras.lib D:\comm\libevent\release_x64_static\lib
copy /Y libevent_openssl.lib D:\comm\libevent\release_x64_static\lib

nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static -f Makefile.nmake.x64.release clean

nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static ZLIB_DIR=D:\comm\zlib\release_x64 -f Makefile.nmake.x64.release clean
注:如果要编译静态库和测试库,可用以下任意一条命令:
nmake -f Makefile.nmake.x64.release
nmake -f Makefile.nmake.x64.release all

nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static -f Makefile.nmake.x64.release
nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static -f Makefile.nmake.x64.release all

nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static ZLIB_DIR=D:\comm\zlib\release_x64 -f Makefile.nmake.x64.release
nmake OPENSSL_DIR=D:\comm\openssl\release_x64_static ZLIB_DIR=D:\comm\zlib\release_x64 -f Makefile.nmake.x64.release all

5 nmake编译结果在VS中使用

5.1 在工程属性的“配置属性”-->“C/C++”-->“预处理器”-->“预处理器定义”中定义宏:
_WIN32_WINNT=0x0501
最新版本可以不定义
5.2 在工程属性的“配置属性”-->“连接器”-->“输入”-->“附加依赖项”添加:
5.2.1 ws2_32.lib shell32.lib advapi32.lib和所用到的“libevent”库;
5.2.2 如果用到“OpenSSL”库时,添加gdi32.lib user32.lib libeay32.lib ssleay32.lib (zlib.lib) 和 libevent_openssl.lib

6 cmake编译准备

6.1 备份“CMakeLists.txt”文件:
copy /Y CMakeLists.txt CMakeLists.txt.bak

7 cmake静态编译

7.1 cmake Debug静态编译
7.1.1 如不需要查看libevent库本身的调试信息,则绕过;否则,请在“CMakeLists.txt”文件中设置:
option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" OFF)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" OFF)
改为:
option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" OFF)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" ON)
7.1.2 编译:
mkdir bld_debug_x64_static_cmake  
cd bld_debug_x64_static_cmake

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\debug_x64_static_cmake

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\debug_x64_static_cmake -DOPENSSL_ROOT_DIR=D:\comm\openssl\debug_x64_static -DOPENSSL_INCLUDE_DIR=D:\comm\openssl\debug_x64_static\include -DOPENSSL_LIBRARIES=D:\comm\openssl\debug_x64_static\lib

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\debug_x64_static_cmake -DOPENSSL_ROOT_DIR=D:\comm\openssl\debug_x64_static -DOPENSSL_INCLUDE_DIR=D:\comm\openssl\debug_x64_static\include -DOPENSSL_LIBRARIES=D:\comm\openssl\debug_x64_static\lib -DZLIB_LIBRARY=D:\comm\zlib\debug_x64\lib\zlib.lib -DZLIB_INCLUDE_DIR=D:\comm\zlib\debug_x64\include -DZLIB_INCLUDE_DIRS=D:\comm\zlib\debug_x64\include -DZLIB_LIBRARIES=D:\comm\zlib\debug_x64\lib

devenv libevent.sln /build Debug /out logfile.txt  
cmake --build . --target INSTALL --config Debug

del CMakeCache.txt  
devenv libevent.sln /clean Debug
cd..
注1:如果不需引入“OpenSSL”、“zlib”库,则请用第1条“cmake”命令;
注2:如果只引入“OpenSSL”,则请用第2条“cmake”命令;
注3:如果引入“OpenSSL”和“zlib”动态库,则请用第3条“cmake”命令;
7.2 cmake Release静态编译
7.2.1 建议在“CMakeLists.txt”文件中设置:
option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" OFF)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" OFF)
改为:
option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" OFF)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" OFF)
7.2.2 编译:
mkdir bld_release_x64_static_cmake  
cd bld_release_x64_static_cmake

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\release_x64_static_cmake

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\release_x64_static_cmake -DOPENSSL_ROOT_DIR=D:\comm\openssl\release_x64_static -DOPENSSL_INCLUDE_DIR=D:\comm\openssl\release_x64_static\include -DOPENSSL_LIBRARIES=D:\comm\openssl\release_x64_static\lib

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\release_x64_static_cmake -DOPENSSL_ROOT_DIR=D:\comm\openssl\release_x64_static -DOPENSSL_INCLUDE_DIR=D:\comm\openssl\release_x64_static\include -DOPENSSL_LIBRARIES=D:\comm\openssl\release_x64_static\lib -DZLIB_LIBRARY=D:\comm\zlib\release_x64\lib\zlib.lib -DZLIB_INCLUDE_DIR=D:\comm\zlib\release_x64\include -DZLIB_INCLUDE_DIRS=D:\comm\zlib\release_x64\include -DZLIB_LIBRARIES=D:\comm\zlib\release_x64\lib

devenv libevent.sln /build Release /out logfile.txt  
cmake --build . --target INSTALL --config Release

del CMakeCache.txt  
devenv libevent.sln /clean Release
cd..
注1:如果不需引入“OpenSSL”、“zlib”库,则请用第1条“cmake”命令;
注2:如果只引入“OpenSSL”,则请用第2条“cmake”命令;
注3:如果引入“OpenSSL”和“zlib”动态库,则请用第3条“cmake”命令;

8 cmake动态编译

8.0 编译前提(2014.12.22)
8.0.1 test相关工程:
test-ratelim.c
test-time.c
test-dumpevents.c // 已修复
编译有问题,所以请在“CMakeLists.txt”文件中设置
option(EVENT__DISABLE_TESTS "If tests should be compiled or not" ON)
8.0.2 regress相关工程( 已修复,请绕过):
regress.c
regress_buffer.c
regress_bufferevent.c
regress_et.c
regress_finalize.c
regress_http.c
regress_iocp.c
regress_listener.c
regress_main.c
regress_minheap.c
regress_thread.c
regress_util.c
编译有问题,所以请在“CMakeLists.txt”文件中设置
option(EVENT__DISABLE_REGRESS "Disable the regress tests" ON)
8.0.3 详见:https://sourceforge.net/p/levent/bugs/341/#2da0
8.0.4 在文件“http.h”的“void evhttp_connection_set_family(struct evhttp_connection *evcon, int family);”前加“EVENT2_EXPORT_SYMBOL”
8.1 cmake Debug动态编译
8.1.1 建议在“CMakeLists.txt”文件中设置:
option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" OFF)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" OFF)
改为:
option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" ON)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" OFF)
如需要查看libevent库本身的调试信息,则改为;
option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" ON)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" ON)
8.1.2 编译:
mkdir bld_debug_x64_cmake  
cd bld_debug_x64_cmake

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\debug_x64

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\debug_x64 -DOPENSSL_ROOT_DIR=D:\comm\openssl\debug_x64 -DOPENSSL_INCLUDE_DIR=D:\comm\openssl\debug_x64\include -DOPENSSL_LIBRARIES=D:\comm\openssl\debug_x64\lib

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\debug_x64 -DOPENSSL_ROOT_DIR=D:\comm\openssl\debug_x64 -DOPENSSL_INCLUDE_DIR=D:\comm\openssl\debug_x64\include -DOPENSSL_LIBRARIES=D:\comm\openssl\debug_x64\lib -DZLIB_LIBRARY=D:\comm\zlib\debug_x64\lib\zdll.lib -DZLIB_INCLUDE_DIR=D:\comm\zlib\debug_x64\include -DZLIB_INCLUDE_DIRS=D:\comm\zlib\debug_x64\include -DZLIB_LIBRARIES=D:\comm\zlib\debug_x64\lib

devenv libevent.sln /build Debug /out logfile.txt  
cmake --build . --target INSTALL --config Debug

del CMakeCache.txt  
devenv libevent.sln /clean Debug
cd..
注1:如果不需引入“OpenSSL”、“zlib”库,则请用第1条“cmake”命令;
注2:如果只引入“OpenSSL”,则请用第2条“cmake”命令;
注3:如果引入“OpenSSL”和“zlib”动态库,则请用第3条“cmake”命令;
8.2 cmake Release动态编译
8.2.1 建议在“CMakeLists.txt”文件中设置:
option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" OFF)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" OFF)
改为:
option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" ON)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" OFF)
8.2.2 编译:
mkdir bld_release_x64_cmake  
cd bld_release_x64_cmake

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\release_x64

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\release_x64 -DOPENSSL_ROOT_DIR=D:\comm\openssl\release_x64 -DOPENSSL_INCLUDE_DIR=D:\comm\openssl\release_x64\include -DOPENSSL_LIBRARIES=D:\comm\openssl\release_x64\lib

cmake .. -G "Visual Studio 12 Win64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=D:\comm\libevent\release_x64 -DOPENSSL_ROOT_DIR=D:\comm\openssl\release_x64 -DOPENSSL_INCLUDE_DIR=D:\comm\openssl\release_x64\include -DOPENSSL_LIBRARIES=D:\comm\openssl\release_x64\lib -DZLIB_LIBRARY=D:\comm\zlib\release_x64\lib\zdll.lib -DZLIB_INCLUDE_DIR=D:\comm\zlib\release_x64\include -DZLIB_INCLUDE_DIRS=D:\comm\zlib\release_x64\include -DZLIB_LIBRARIES=D:\comm\zlib\release_x64\lib

devenv libevent.sln /build Release /out logfile.txt  
cmake --build . --target INSTALL --config Release

del CMakeCache.txt  
devenv libevent.sln /clean Release
cd..
注1:如果不需引入“OpenSSL”、“zlib”库,则请用第1条“cmake”命令;
注2:如果只引入“OpenSSL”,则请用第2条“cmake”命令;
注3:如果引入“OpenSSL”和“zlib”动态库,则请用第3条“cmake”命令;

9 cmake编译结果在VS中使用

9.1 在工程属性的“配置属性”-->“C/C++”-->“预处理器”-->“预处理器定义”中定义宏:
9.1.1 定义宏:
_WIN32_WINNT=0x0501
最新版本可以不定义
9.1.2 根据文件“visibility.h”以下两条语句:
#if defined(event_EXPORTS) || defined(event_extra_EXPORTS) || defined(event_core_EXPORTS)
#if defined(EVENT__NEED_DLLIMPORT) && !defined(EVENT_BUILDING_REGRESS_TEST)
在使用动态库时定义宏:
EVENT__NEED_DLLIMPORT
9.2 在工程属性的“配置属性”-->“连接器”-->“输入”-->“附加依赖项”添加:
9.2.1 ws2_32.lib shell32.lib advapi32.lib和所用到的“libevent”库;
9.2.2 如果用到“OpenSSL”库时,添加gdi32.lib user32.lib libeay32.lib ssleay32.lib (zlib.lib/zdll.lib)

10 参考文章

/Ox(完全优化)
http://msdn.microsoft.com/zh-cn/library/vstudio/59a3b321.aspx
按字母顺序列出的编译器选项
http://msdn.microsoft.com/zh-cn/library/vstudio/fwkeyyhe.aspx
按类别列出的编译器选项
http://msdn.microsoft.com/zh-cn/library/vstudio/19z1t1wy.aspx
assert (CRT)
http://msdn.microsoft.com/zh-cn/library/9sb57dw4.aspx
Windows下编译libevent - happyAnger6的专栏 - 博客频道 - CSDN.NET
http://blog.csdn.net/happyanger6/article/details/7272241

11 阅读资料

Libevent源码分析 - luotuo44的专栏
http://blog.csdn.net/luotuo44/article/category/2435521
从 bufferevent 实现学习 Libevent 的使用
http://www.tuicool.com/articles/muAZBf
Libevent参考手册(最好阅读)
http://blog.csdn.net/laoyi19861011/article/category/831215
libevent参考手册第6a章:Bufferevent:高级话题
http://www.cppblog.com/mysileng/archive/2013/02/05/197746.html
Libevent参考手册第9章:使用libevent的DNS:高层和底层功能
http://www.360doc.com/content/14/0102/10/15064667_341888075.shtml
Libevent参考手册
http://www.cppblog.com/mysileng/category/20374.html
libevent参考手册(全)
http://www.cnblogs.com/wangchenxicool/category/319479.html
http://blog.sina.com.cn/s/articlelist_1457448730_0_1.html
libevent源码深度剖析
http://blog.csdn.net/sparkliang/article/category/660506
libevent源码分析
http://www.cnblogs.com/hustcat/archive/2010/08/31/1814022.html
libevent源码浅析 版本1
http://simohayha.iteye.com/category/10946
libevent源码浅析 版本2
http://godorz.info/tag/libevent/
android上libevent dns解析的一个bug修复
http://www.2cto.com/kf/201404/291023.html
libevent功能使用简介
http://www.360doc.com/content/13/0728/13/13308646_303116432.shtml
高性能、高并发TCP服务器(多线程调用libevent)
http://blog.csdn.net/dai_jing/article/details/38147813
使用libevent异步解析dns
http://blog.csdn.net/foruok/article/details/22738217
SPServer : 一个基于线程池(包括HAHS和LF)的高并发 server 框架
http://iunknown.iteye.com/blog/59804

在 Windows 平台上,你可以使用 Visual Studio 编译 LAME 源码。下面是使用 Visual Studio 2019 编译 LAME 源码的步骤: 1. 下载 LAME 源码。你可以从 LAME 官方网站下载最新版本的 LAME 源码。 2. 安装 Visual Studio 2019。你可以从 Visual Studio 官方网站下载最新版本的 Visual Studio 2019。 3. 打开 Visual Studio 2019,并选择“打开项目或文件”菜单,然后选择 LAME 源码目录下的 `lame.sln` 文件。 4. 在 Visual Studio 中,选择“生成”菜单,然后选择“生成解决方案”命令。这个命令会使用 Visual Studio 工具链编译 LAME 源码,生成针对 Windows 平台的库文件。 5. 编译完成后,在 LAME 源码目录下的 `libmp3lame` 目录中会生成 `libmp3lame.lib` 和 `libmp3lame.dll` 两个文件。其中,`libmp3lame.lib` 是静态链接库文件,`libmp3lame.dll` 是动态链接库文件。 6. 将 `libmp3lame.lib` 和 `libmp3lame.dll` 文件拷贝到你的项目目录下,并在 Visual Studio 中设置头文件和库文件的路径,以便正确地链接这些库文件。具体的设置方法可以参考 Visual Studio 的文档。 注意,如果你使用的是其他版本的 Visual Studio,具体的编译方法可能会有所不同。在编译时,你需要根据实际情况选择目标平台和编译选项。你可以使用 Visual Studio 命令提示符进入 LAME 源码目录,然后执行以下命令: ``` nmake -f Makefile.msvc ``` 这个命令会使用 Visual Studio 工具链编译 LAME 源码,生成针对 Windows 平台的库文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值