2023年12月21日发(作者:)

Windows上编译CURL含有zlib,openssl

准备工作

A、下载zlib

zlib可以使得HTTP请求支持gzip压缩,其地址如下:

官网:/

下载地址:/

B、下载openssl

opensll使用与支持SSL,例如HTTPS的请求。

官网:

下载地址:/source/

C.、下载curl

官网:

下载地址:在/选择你所想要的版本,这儿选用7.35.0版本 [/download/]

D.、下载ActivePerl

官网:/activeperl/downloads

请注意根据自己的系统版本【32,64】选择不同的安装包【链接失效时用迅雷可下载】

下载地址:/ActivePerl/releases/5.16.0.1600/

X64下载地址:/ActivePerl/releases/5.16.0.1600/

编译依赖库

A.、安装activePerl

直接双击安装,用默认设置就可以了。

B、 解压zlib、openssl、curl源码文件到在一个目录下;

C.、编译zlib

从开始菜单,选择Microsoft Visual Studio 2008 > Visual Studio Tools > Visual Studio

2008 Command Prompt,弹出的控制台窗口输入

“nmake -f win32/ OBJA="" ”;

D、编译openssl

将当前目录切换到openssl-1.0.1f,输入下面执行下面的命令“”;

注意:若提示文件不存在,请检查解压缩中是否丢失文件。

编译Curl库

使用命令编译

若希望使用为动态库版本,推荐使用该编译方式。因为编译的静态版本在测试时容易出现静态库不能链接的问题。默认情况下,该编译的版本为x86 32位系统版本。

A、编译curllib

之前打开的控制台命令窗口不要关闭,将当前目录切换到curl的的目录curl-7.35.0lib下,然后依次输入一下的命令:

set OPENSSL_PATH=....openssl-1.0.1f

set ZLIB_PATH=....zlib-1.2.8

nmake -f 9 CFG=release-dll-ssl-dll-zlib-dll

注意 6是VC6.0的版本,VC8是VC2005,VC9是VS2008。

B、配置编译选项

CFG是配置编译结果选项,其具体内容如下:

Usage: nmake /f 9 CFG=

where is one of:

release - release static library

release-ssl - release static library with ssl

release-zlib - release static library with zlib

release-ssl-zlib - release static library with ssl and zlib

release-ssl-ssh2-zlib - release static library with ssl, ssh2 and zlib

release-ssl-dll - release static library with dynamic ssl

release-zlib-dll - release static library with dynamic zlib

release-ssl-dll-zlib-dll - release static library with dynamic ssl and dynamic zlib

release-dll - release dynamic library

release-dll-ssl-dll - release dynamic library with dynamic ssl

release-dll-zlib-dll - release dynamic library with dynamic zlib

release-dll-ssl-dll-zlib-dll - release dynamic library with dynamic ssl and dynamic zlib

debug - debug static library

debug-ssl - debug static library with ssl

debug-zlib - debug static library with zlib

debug-ssl-zlib - debug static library with ssl and zlib

debug-ssl-ssh2-zlib - debug static library with ssl, ssh2 and zlib

debug-ssl-dll - debug static library with dynamic ssl

debug-zlib-dll - debug static library with dynamic zlib

debug-ssl-dll-zlib-dll - debug static library with dynamic ssl and dynamic zlib

debug-dll - debug dynamic library

debug-dll-ssl-dll - debug dynamic library with dynamic ssl

debug-dll-zlib-dll - debug dynamic library with dynamic zlib1

debug-dll-ssl-dll-zlib-dll - debug dynamic library with dynamic ssl and dynamic zlib

can be left blank in which case all is assumed

使用VS编译

本文档使用VS编译x86 Release版的Curl静态库文件为例。

A、打开Curl源码文件,使用VS开发工具打开“.”。

B、打开后,右击工程“libcurl”,选择“属性”,选择“Lib Release”;

C、在“C/C++”列项中选择“常规”,向“附加包含目录”中添加SSL头文件所在的文件夹;

D、在“C/C++”列项中选择“预处理器”,向“预处理器定义”中添加宏定义“BUILDING_LIBCURL”和“CURL_STATICLIB”;

E、在“C/C++”列项中选择“代码生成”,将“运行时库”更改 为“多线程(/MT)”;

F、向工程“libcurl”添加或创建头文件“opensslDefine.h”,打开后输入下面代码

#ifndef OPENSSL_DEFINE_H

#define OPENSSL_DEFINE_H

#define USE_SSLEAY

#define USE_OPENSSL

#define USE_SSL

#endif

G、在“urldata.h”、“ftp.h”、“http.h”、“hostcheck.c”、“openssl.h”、“url.c”等文件添加代码“#include "opensslDefine.h” ”引用之前添加或创建的头文件。

H、编译工程“libcurl”;

注意:编译可能提示“opensslDefine.h”找不到,请到路径“.vsvc6lib”中将文件剪切到路径“.lib”; 步骤E中的设置请注意,若是Debug版本,请选择“多线程调试(MTD)”。

LibCurl测试

因生成的静态库为x86 32位版本,测试程序应该是32位程序。

A、拷贝CURL静态库

将路径“.vsvc6liblib-release”下静态库文件“”拷贝到测试工程库文件夹路径下;

B、拷贝CURL头文件

将路径“.include”下文件夹“curl”拷贝到测试工程头文件夹路径下;

C、拷贝OpenSSL静态库

将openssl源码文件夹下路径“.out32”下静态库文件“”和“”拷贝到测试工程库文件夹路径下;

D、添加附加头文件目录到测试工程;

E、添加附加库目录到测试工程;

F、添加链接库文件“”“”“”“”“ws2_”到测试工程;

G、向测试工程中添加预处理宏“BUILDING_LIBCURL”;

H、将“运行时库”更改 为“多线程(/MT)”;