libevhtp windows下编译 5C

有人在windows下编译过libevhtp吗,求编译过程及编译库

2个回答

安装OpenSSL
本文中用到的OpenSSL版本是openssl-OpenSSL_1_0_1u (开始使用的版本是openssl-OpenSSL_1_1_0,但是在源码中没有找到ms\do_ms)。

构建需求(Visual C++)
In addition to the requirements and instructions listed in INSTALL,
this are required as well:

You need Perl. We recommend ActiveState Perl, available from https://www.activestate.com/ActivePerl.
You also need the perl module Text::Template, available on CPAN. Please read NOTES.PERL for more information.
You need a C compiler. OpenSSL has been tested to build with these:

Visual C++
Netwide Assembler, a.k.a. NASM, available from http://www.nasm.us,
is required if you intend to utilize assembler modules. Note that NASM is the only supported assembler. The Microsoft provided assembler is NOT
supported.

本机的部分环境变量如下:

%SystemRoot%\system32;
%SystemRoot%;
D:\Strawberry\c\bin;
D:\Strawberry\perl\site\bin;
D:\Strawberry\perl\bin;
C:\Program Files (x86)\NASM;

构建OpenSSL
打开Visual Studio Command Prompt (2010) ,依次输入下列命令:

$ cd openssl-OpenSSL_1_0_1u
$ perl Configure VC-WIN32 --prefix="F:\ThirdParty\openssl\openssl" --openssldir="F:\ThirdParty\openssl\ssl"
$ ms\do_ms
$ nmake -f ms\nt.mak
$ nmake -f ms\nt.mak test
$ nmake -f ms\nt.mak install
Configure命令对安装进行配置,其中VC-WIN32是指定构建的平台,可选的参数有(选择其中之一):VC-WIN32 | VC-WIN64A | VC-WIN64I | VC-CE ,如果想要构建debug版本使用debug-VC-WIN32参数即可。--prefix参数指定库文件和头文件(lib、include、bin)的安装位置,如果不指定将会默认安装到%ProgramFiles(86)%\OpenSSL目录。--openssldir参数指定OpenSSL的安装路径,如果不指定将会默认安装到%CommonProgramFiles(86)%\SSL目录。
do_ms是源代码ms目录下的批处理文件,如果想要构建64位的库使用ms\do_win64a命令。
nmake用于构建源码,默认构建的静态库,如果想要构建动态库可以指定使用ms\ntdll.mak 。
更详细的安装说明请查看OpenSSL源文件目录下的INSTALL 、NOTES.WIN和NOTES.PERL文件,但是千万不要盲目相信源目录下的安装方法。

安装libevent
本例中使用的libevent版本是2.0.22-stable ,使用nmake编译。更新版本已经支持使用CMake编译。

编译32位库打开Visual Studio Command Prompt (2010) ,编译64位库打开Visual Studio x64 Win64 Command Prompt (2010) ,依次输入下列命令:

$ cd
$ nmake -f makefile.nmake

可以跟根据实际情况修改makefile.nmake文件,已知可以修改的配置如下:

WATCH OUT! This makefile is a work in progress. It is probably missing

tons of important things. DO NOT RELY ON IT TO BUILD A GOOD LIBEVENT.

By default, Makefile.nmake builds without OpenSSL, as before. But if you uncomment the line:

OPENSSL_DIR=F:\ThirdParty\openssl\openssl

!IFDEF OPENSSL_DIR
SSL_CFLAGS=/I$(OPENSSL_DIR)\include /DEVENT__HAVE_OPENSSL
!ELSE
SSL_CFLAGS=
!ENDIF

Needed for correctness

#CFLAGS=/IWIN32-Code /Iinclude /Icompat /DWIN32 /DHAVE_CONFIG_H /I.
CFLAGS=/IWIN32-Code /Iinclude /Icompat /DWIN32 /DHAVE_CONFIG_H /I. $(SSL_CFLAGS)

添加WIN32_WINNT宏定义(根据系统平台更改值,好像已经可以省略)

CFLAGS=$(CFLAGS) /D_WIN32_WINNT=0x0501

消除DEPRECATE警告

CFLAGS=$(CFLAGS) /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE

For optimization and warnings

debug模式/Od(禁用优化)

CFLAGS=$(CFLAGS) /Od /W3 /wd4996 /nologo

release模式/Ox(完全优化)

CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo

XXXX have a debug mode (debug模式添加-D_DEBUG)

CFLAGS=$(CFLAGS) -D_DEBUG

debug版本添加调试信息,x86可以使用/ZI

#CFLAGS=$(CFLAGS) /ZI

debug版本添加调试信息,x64可以使用/Zi

CFLAGS=$(CFLAGS) /Zi

LIBFLAGS=/nologo

64位库添加/MACHINE:X64

LIBFLAGS=$(LIBFLAGS) /MACHINE:X64

CORE_OBJS=event.obj buffer.obj bufferevent.obj bufferevent_sock.obj \
bufferevent_pair.obj listener.obj evmap.obj log.obj evutil.obj \
strlcpy.obj signal.obj bufferevent_filter.obj evthread.obj \
bufferevent_ratelim.obj evutil_rand.obj
WIN_OBJS=win32select.obj evthread_win32.obj buffer_iocp.obj \
event_iocp.obj bufferevent_async.obj
EXTRA_OBJS=event_tagging.obj http.obj evdns.obj evrpc.obj

添加输出文件*_openssl.lib *_openssl.obj

!IFDEF OPENSSL_DIR
SSL_OBJS=bufferevent_openssl.obj
SSL_LIBS=libevent_openssl.lib
!ELSE
SSL_OBJS=
SSL_LIBS=
!ENDIF

添加pthreads输出文件

THR_OBJS=evthread.obj
THR_LIBS=libevent_pthreads.lib

添加$(SSL_OBJS)

ALL_OBJS=$(CORE_OBJS) $(WIN_OBJS) $(EXTRA_OBJS) $(SSL_OBJS) $(THR_OBJS)

添加$(SSL_LIBS)

STATIC_LIBS=libevent_core.lib libevent_extras.lib libevent.lib $(SSL_LIBS) $(THR_LIBS)

all: static_libs tests

static_libs: $(STATIC_LIBS)

libevent_core.lib: $(CORE_OBJS) $(WIN_OBJS)
lib $(LIBFLAGS) $(CORE_OBJS) $(WIN_OBJS) /out:libevent_core.lib

libevent_extras.lib: $(EXTRA_OBJS)
lib $(LIBFLAGS) $(EXTRA_OBJS) /out:libevent_extras.lib

libevent.lib: $(CORE_OBJS) $(WIN_OBJS) $(EXTRA_OBJS)
lib $(LIBFLAGS) $(CORE_OBJS) $(EXTRA_OBJS) $(WIN_OBJS) /out:libevent.lib

how to make "libevent_openssl"

libevent_openssl.lib: $(SSL_OBJS)
lib $(LIBFLAGS) $(SSL_OBJS) /out:libevent_openssl.lib

how to make "libevent_pthreads"

libevent_pthreads.lib: $(THR_OBJS)
lib $(LIBFLAGS) $(THR_OBJS) /out:libevent_pthreads.lib

添加clean

clean:
del $(ALL_OBJS)
del $(STATIC_LIBS)
cd test
$(MAKE) /F Makefile.nmake clean
cd ..

tests:
cd test

$(MAKE) /F Makefile.nmake

如果libevhtp支持cmake时提示LIBEVENT_PTHREADS_LIBRARY(ADVANCED)错误则需要编译输出libevent_pthreads.lib ,否则不需要。

安装libevhtp
安装libevhtp是个很麻烦的过程,遇到了很多问题,经过无数次的失败与重试,终于编译成功了。

打开命令提示符工具或Visual Studio Command Promp ,依次输入下列命令:

$ cd /build
$ cmake -G "MinGW Makefiles" $(params) ..
$ mingw32-make # 或执行 nmake

可以使用cmake-gui工具替换cmake命令,其中$(params)参数的详细信息如下(Commandline options块中,不需全部输入,仅供参考):

Commandline options:
-DLIBEVENT_INCLUDE_DIR:PATH="F:/ThirdParty/libevent/include" -DCMAKE_C_FLAGS:STRING="" -DCMAKE_LINKER:FILEPATH="D:/Strawberry/c/bin/ld.exe" -DCMAKE_CXX_FLAGS_DEBUG:STRING="-g" -DCMAKE_OBJCOPY:FILEPATH="D:/Strawberry/c/bin/objcopy.exe" -DCMAKE_CXX_STANDARD_LIBRARIES:STRING="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32" -DEVHTP_DISABLE_EVTHR:BOOL="1" -DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING="-O2 -g -DNDEBUG" -DCMAKE_C_STANDARD_LIBRARIES:STRING="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32" -DCMAKE_RANLIB:FILEPATH="D:/Strawberry/c/bin/ranlib.exe" -DHAS_SYS_ONIG:FILEPATH="HAS_SYS_ONIG-NOTFOUND" -DLIBEVENT_CORE_LIBRARY:FILEPATH="F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent_core.lib" -DEVHTP_DISABLE_SSL:BOOL="0" -DLIBEVENT_LIBRARY:FILEPATH="F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent.lib" -DLIBEVENT_EXTRA_LIBRARY:FILEPATH="F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent_extras.lib" -DEVHTP_DISABLE_REGEX:BOOL="1" -DCMAKE_STRIP:FILEPATH="D:/Strawberry/c/bin/strip.exe" -DCMAKE_AR:FILEPATH="D:/Strawberry/c/bin/ar.exe" -DCMAKE_INSTALL_PREFIX:PATH="C:/Program Files (x86)/libevhtp" -DCMAKE_CXX_FLAGS_RELEASE:STRING="-O3 -DNDEBUG" -DLIB_WS32:FILEPATH="C:/Windows/System32/ws2_32.dll" -DCMAKE_CXX_FLAGS:STRING="" -DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING="-O2 -g -DNDEBUG" -DCMAKE_NM:FILEPATH="D:/Strawberry/c/bin/nm.exe" -DCMAKE_RC_COMPILER:FILEPATH="D:/Strawberry/c/bin/windres.exe" -DCMAKE_COLOR_MAKEFILE:BOOL="1" -DLIB_EAY:FILEPATH="F:/ThirdParty/openssl/openssl/lib/libeay32.lib" -DSSL_EAY:FILEPATH="F:/ThirdParty/openssl/openssl/lib/ssleay32.lib" -DCMAKE_C_FLAGS_RELEASE:STRING="-O3 -DNDEBUG" -DLIBEVENT_OPENSSL_LIBRARY:FILEPATH="F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent_openssl.lib" -DEVHTP_BUILD_SHARED:BOOL="0" -DCMAKE_C_FLAGS_DEBUG:STRING="-g" -DCMAKE_CXX_FLAGS_MINSIZEREL:STRING="-Os -DNDEBUG" -DCMAKE_OBJDUMP:FILEPATH="D:/Strawberry/c/bin/objdump.exe" -DCMAKE_C_FLAGS_MINSIZEREL:STRING="-Os -DNDEBUG" -DCMAKE_SH:FILEPATH="CMAKE_SH-NOTFOUND" -DCMAKE_C_COMPILER:FILEPATH="D:/Strawberry/c/bin/gcc.exe" -DOPENSSL_INCLUDE_DIR:PATH="F:/ThirdParty/openssl/openssl/include" -DCMAKE_MAKE_PROGRAM:FILEPATH="D:/Qt/Qt5.5.0/Tools/mingw492_32/bin/mingw32-make.exe" -DLIBEVENT_PTHREADS_LIBRARY:FILEPATH="F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent_pthreads.lib" -DCMAKE_CXX_COMPILER:FILEPATH="D:/Strawberry/c/bin/g++.exe"

Cache file:
LIBEVENT_INCLUDE_DIR:PATH=F:/ThirdParty/libevent/include
CMAKE_C_FLAGS:STRING=
CMAKE_LINKER:FILEPATH=D:/Strawberry/c/bin/ld.exe
CMAKE_CXX_FLAGS_DEBUG:STRING=-g
CMAKE_OBJCOPY:FILEPATH=D:/Strawberry/c/bin/objcopy.exe
CMAKE_CXX_STANDARD_LIBRARIES:STRING=-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
EVHTP_DISABLE_EVTHR:BOOL=1
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
CMAKE_C_STANDARD_LIBRARIES:STRING=-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
CMAKE_RANLIB:FILEPATH=D:/Strawberry/c/bin/ranlib.exe
HAS_SYS_ONIG:FILEPATH=HAS_SYS_ONIG-NOTFOUND
LIBEVENT_CORE_LIBRARY:FILEPATH=F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent_core.lib
EVHTP_DISABLE_SSL:BOOL=0
LIBEVENT_LIBRARY:FILEPATH=F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent.lib
LIBEVENT_EXTRA_LIBRARY:FILEPATH=F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent_extras.lib
EVHTP_DISABLE_REGEX:BOOL=1
CMAKE_STRIP:FILEPATH=D:/Strawberry/c/bin/strip.exe
CMAKE_AR:FILEPATH=D:/Strawberry/c/bin/ar.exe
CMAKE_INSTALL_PREFIX:PATH=C:/Program Files (x86)/libevhtp
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
LIB_WS32:FILEPATH=C:/Windows/System32/ws2_32.dll
CMAKE_CXX_FLAGS:STRING=
CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG
CMAKE_NM:FILEPATH=D:/Strawberry/c/bin/nm.exe
CMAKE_RC_COMPILER:FILEPATH=D:/Strawberry/c/bin/windres.exe
CMAKE_COLOR_MAKEFILE:BOOL=1
LIB_EAY:FILEPATH=F:/ThirdParty/openssl/openssl/lib/libeay32.lib
SSL_EAY:FILEPATH=F:/ThirdParty/openssl/openssl/lib/ssleay32.lib
CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG
LIBEVENT_OPENSSL_LIBRARY:FILEPATH=F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent_openssl.lib
EVHTP_BUILD_SHARED:BOOL=0
CMAKE_C_FLAGS_DEBUG:STRING=-g
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
CMAKE_OBJDUMP:FILEPATH=D:/Strawberry/c/bin/objdump.exe
CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG
CMAKE_SH:FILEPATH=CMAKE_SH-NOTFOUND
CMAKE_C_COMPILER:FILEPATH=D:/Strawberry/c/bin/gcc.exe
OPENSSL_INCLUDE_DIR:PATH=F:/ThirdParty/openssl/openssl/include
CMAKE_MAKE_PROGRAM:FILEPATH=D:/Qt/Qt5.5.0/Tools/mingw492_32/bin/mingw32-make.exe
LIBEVENT_PTHREADS_LIBRARY:FILEPATH=F:/ThirdParty/libevent/2.0.22_lib/x86_release/libevent_pthreads.lib

CMAKE_CXX_COMPILER:FILEPATH=D:/Strawberry/c/bin/g++.exe

cmake生成成功后输出的信息如下,供大家参考:

The C compiler identification is GNU 4.9.2
The CXX compiler identification is GNU 4.9.2
Check for working C compiler: D:/Strawberry/c/bin/gcc.exe
Check for working C compiler: D:/Strawberry/c/bin/gcc.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: D:/Strawberry/c/bin/g++.exe
Check for working CXX compiler: D:/Strawberry/c/bin/g++.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
CMake Warning (dev) at examples/CMakeLists.txt:3 (add_executable):
Policy CMP0037 is not set: Target names should not be reserved and should
match a validity pattern. Run "cmake --help-policy CMP0037" for policy
details. Use the cmake_policy command to set the policy and suppress this

warning.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问