windows 7 下编译 nopoll

来源:互联网 发布:java rest接口实例 编辑:程序博客网 时间:2024/06/14 04:34

编译环境:

windows 7 64位

VS 2013 Ultimate

openssl-1.0.2a

nopoll-0.2.8.b184

编译步骤:

1. nopoll官网提供了二进制安装包,不过不知为什么无法直接用,所以还是得手动编译个

2. nopoll依赖openssl,所以先编译openssl:

1)下载http://www.openssl.org/source/openssl-1.0.2a.tar.gz

2)安装perl,http://downloads.activestate.com/ActivePerl/releases/5.20.1.2000/ActivePerl-5.20.1.2000-MSWin32-x64-298557.msi

3)解压后,阅读INSTALL.W64安装说明:

 To build for Win64/x64: > perl Configure VC-WIN64A > ms\do_win64a > nmake -f ms\ntdll.mak > cd out32dll > ..\ms\test

         4) 第三步的ms\do_win65a和nmake -f ms\ntdll.mak必须要用vs的控制台程序来执行,否则会出错

                          Clipboard Image.png

        5)编译完成通过后,执行nmake -f ms\ntdll.mak install来生成最终发布文件,

生成位置默认是在usr/local/里,但windows下没有这个目录,

所以Perl把ssl生成到当前控制台所在分区的根目录了(如源码在d:/openssl/,则会生成到D:/usr/local/)

3.用编译好的openssl库来编译Nopoll

nopoll虽然提供了Makefile.win,但我试了下,发现并不能一键编译,会提示缺少versions.mk和config.mk(这2个文件最后在nopoll的svn仓库里找到),补上这2个文件后再次执行nmake,会提示./prepare-nsh.sh permission denied(win平台执行sh文件?)

按官方的编译方法失败后,只能自行建工程编译了:

1)新建一个vs工程,取名libnopoll

2)添加 nopoll-0.2.8.b184/src目录的源码文件到工程里

这里要改下nopoll_config.h(此文件应该是自动生成的,我们要手动修改一个出来)

做了几个修改:

//#define NOPOLL_OS_UNIX (1)

#define NOPOLL_OS_WIN32 (1)

#define R_OK 4

#define W_OK 2

//#define NOPOLL_HAVE_VASPRINTF (1)

/* * Nopoll Library nopoll_config.h * Platform dependant definitions. * * This is a generated file.  Please modify 'configure.in' */#ifndef __NOPOLL_CONFIG_H__#define __NOPOLL_CONFIG_H__/** * \addtogroup nopoll_decl_module * @{ *//** * @brief Allows to convert integer value (including constant values) * into a pointer representation. * * Use the oposite function to restore the value from a pointer to a * integer: \ref PTR_TO_INT. * * @param integer The integer value to cast to pointer. * * @return A \ref noPollPtr reference. */#ifndef INT_TO_PTR#define INT_TO_PTR(integer)   ((noPollPtr) (long) ((int)integer))#endif/** * @brief Allows to convert a pointer reference (\ref noPollPtr), * which stores an integer that was stored using \ref INT_TO_PTR. * * Use the oposite function to restore the pointer value stored in the * integer value. * * @param ptr The pointer to cast to a integer value. * * @return A int value. */#ifndef PTR_TO_INT#define PTR_TO_INT(ptr) ((int) (long) (ptr))#endif/** * @brief Allows to get current platform configuration. This is used * by Nopoll library but could be used by applications built on top of * Nopoll to change its configuration based on the platform information. *///#define NOPOLL_OS_UNIX (1)#define NOPOLL_OS_WIN32 (1)#define R_OK 4#define W_OK 2/** * @internal Allows to now if the platform support vasprintf * function. Do not use this macro as it is supposed to be for * internal use. *///#define NOPOLL_HAVE_VASPRINTF (1)/** * @brief Indicates that this platform have support for 64bits. */#define NOPOLL_64BIT_PLATFORM (1)/* @} */#endif

3)配置编译环境

Clipboard Image.png

Clipboard Image.png

添加openssl的include、nopoll的src到包含目录;

添加上一步生成的ssl/lib目录 到 库目录;

执行 生成项目,就得到了libnopoll.lib文件;

4.测试libnopoll.lib是否可用:

新建测试项目,一样是Clipboard Image.png

添加nopoll官方的example代码,https://dolphin.aspl.es/svn/publico/nopoll/trunk/test/nopoll-regression-listener.c;

复制 /test的pem、crt、key文件到工程目录里;

Clipboard Image.png

然后是附加依赖项:

Clipboard Image.png

之后就可以编译 运行了:

Clipboard Image.png

看样子是成功了。

最后客户端的例子也试着编译下,工程配置和server的一样

!! 编译时出现error:

Clipboard Image.png

照着反馈做即可,在文件头添加一个define 

#define _CRT_SECURE_NO_WARNINGS

Clipboard Image.png

unlink改成_unlink呗;

VERSION可能是要自己定义,也定义一个,之后就顺利编译出来了。

不过运行的时候又出现报错,

Clipboard Image.png

问题就是windows下没有linux的diff工具,先把相关的几行代码屏蔽掉先把,再次编译运行

Clipboard Image.png

good,客户端和服务端协同工作了。


编译debug版的openssl :  http://blog.csdn.net/wangxvfeng101/article/details/7261264

0 0
原创粉丝点击