win10+cmake+vs2019编译64位libevent
概要:
- 使用平台:win10_64位
- 使用工具:cmake、vs2019
- 目的:在windows下编译libevent的库文件
- 可以实现任意版本的libevent手动编译
工具依赖
1.libevent下载,下载链接:
https://github.com/libevent/libevent.git
2.openssl下载,下载链接:
https://github.com/openssl/openssl
3.MbedTLS下载,下载链接:
https://github.com/ARMmbed/mbedtls.git
4.perl下载,下载链接:
perl有两种解决方案:
- 使用ActivePerl:https://www.activestate.com/products/perl/downloads/
- 使用strawberryperl:strawberryperl
5.nasm下载:https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/
工具说明:
编译openssl需要依赖perl、nasm,具体详情可以访问github中的相关介绍,相关链接:https://github.com/openssl/openssl/blob/master/NOTES-Windows.txt
Quick start
-----------
1. Install Perl
2. Install NASM
3. Make sure both Perl and NASM are on your %PATH%
4. Use Visual Studio Developer Command Prompt with administrative privileges,
choosing one of its variants depending on the intended architecture.
Or run "cmd" and execute "vcvarsall.bat" with one of the options x86,
x86_amd64, x86_arm, x86_arm64, amd64, amd64_x86, amd64_arm, or amd64_arm64.
This sets up the environment variables needed for nmake.exe, cl.exe, etc.
See also
<https://docs.microsoft.com/cpp/build/building-on-the-command-line>
5. From the root of the OpenSSL source directory enter
perl Configure VC-WIN32 if you want 32-bit OpenSSL or
perl Configure VC-WIN64A if you want 64-bit OpenSSL or
perl Configure to let Configure figure out the platform
6. nmake
7. nmake test
8. nmake install
openssl安装过程中需要注意的事项为:
- 检查perl的版本,以及perl是否在环境变量path中,查看perl版本时需注意,显示的版本是否与你预期的相同;例如我在编译时,就出现了perl版本与我预期版本不一致的问题,我的问题导致的原因是我安装mysys2,在mysys中安装过perl,而且系统环境变量中指向该perl的路径在我后来安装的perl的路径之前,这就导致了我使用perl时候出现的版本问题。其次避免使用perl的时候出错,建议使用strawberryperl
- 检查nasm是否在系统环境变量中
- perl、nasm安装成功后,按照上面的操作教程就可以编译成功openssl,至于你想编译32位、还是64位的就可以自己选择。
openssl最简单的安装方式是:使用python,用python安装openssl就存在头文件与lib文件,不影响使用。不想自己编译openssl的同志,完全可以使用python的安装方式去安装
编译 MbedTLS
编译MbedTLS是必不可少的步骤,下载好MbedTLS源文件后使用cmake_gui生成vs的工程,然后使用vs编译MbedTLS即可。需要注意的事情是,cmake中使用config之后记得更改install的路径,因为在vs中编译的时候默认没有权限在改默认路径中创建文件夹以及复制生成好的lib文件;
编译libevent
1.如上链接下载libevent的源代码
2.使用cmake
3.如果没有找到MbedTLS报错,配置MbedTLS的路径:
该路径为上面编译MbedTLS后其lib所在文件路径