在 Windows 上构建支持 SSL 的 libcurl [英] Building libcurl with SSL support on Windows

查看:38
本文介绍了在 Windows 上构建支持 SSL 的 libcurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Win32 C++ 应用程序中使用 libcurl.

I'm using libcurl in a Win32 C++ application.

我将 curllib.vcproj 项目添加到我的解决方案中,并将我的其他项目设置为依赖它.

I have the curllib.vcproj project added to my solution and set my other projects to depend on it.

如何在启用 SSL 支持的情况下构建它?

How do I build it with SSL support enabled?

推荐答案

好吧,既然这个帖子失败得很厉害,我只好自己深入研究这个问题.

Well, since this post failed badly, I had to dig into the matter myself.

还可以查看其他答案和评论,以获取有关其他版本等的更多信息.

自从我发布了这个 Q 之后,似乎可以从 curl 主页获得现成的二进制文件.查看詹姆斯的回答.

-

预处理器

需要将以下两个符号提供给预处理器才能为 libcurl 启用 SSL:

The following two symbols need to be fed to the preprocessor to enable SSL for libcurl:

USE_SSLEAY
USE_OPENSSL

(libcurl 使用 OpenSSL 来支持 SSL)

(libcurl uses OpenSSL for SSL support)

或者,可以将符号直接添加到 libcurl 中名为 setup.h 的文件中,但我不太乐意修改 3rd 方发行版中的代码,除非我真的必须这样做.

Alternatively the symbols can be added directly to a file called setup.h in libcurl, but I'm not too happy about modifying code in 3rd party distributions unless I really have to.

重建 libcurl 库,我现在遇到了一些关于未找到 OpenSSL 包含文件的错误.当然,因为我还没有正确设置 OpenSSL 发行版.

Rebuilding the libcurl library, I now got some errors about OpenSSL include files not being found. Naturally, since I haven't set up the OpenSSL distribution properly yet.

编译 OpenSSL 二进制文件

我下载了 OpenSSL 0.9.8 源发行版并解压了它.

I downloaded the OpenSSL 0.9.8 source distribution and unpacked it.

在源代码分发的根目录中有一个名为 INSTALL.W32 的文件,它描述了如何编译 OpenSSL 二进制文件.构建链需要 perl,所以我安装了最新版本的 ActivePerl.

In the root of the source distribution there's a file called INSTALL.W32 which describes how to compile the OpenSSL binaries. The build chain requires perl, so I installed the latest version of ActivePerl.

我在构建过程中遇到了一些问题,这可能不适用于所有系统,但我会在这里进行介绍,以防有人遇到相同的情况.

I had some trouble with the build, which might not be applicable to all systems, but I'll go through it here in case somebody experiences the same.

根据 INSTALL.W32:

According to INSTALL.W32:

在当前目录设置为源分发根目录的情况下运行以下命令行任务:

Run the following commandline tasks with current directory set to the source distribution root:

1> perl Configure VC-WIN32 --prefix=c:/some/openssl/dir

(其中c:/some/openssl/dir"应替换为安装 OpenSSL 的目录.不要在此路径中使用空格.在这种情况下,进一步的编译将失败)

(Where "c:/some/openssl/dir" should be replaced by the dir where OpenSSL should be installed. Don't use spaces in this path. The compilation further ahead will fail in that case)

2> msdo_ms

对我来说,这一步一开始并不成功,因为我缺少环境变量 OSVERSION 和 TARGETCPU.我将它们分别设置为 5.1.2600x86.您可能会抱怨 OSVERSION 疯狂",但仔细观察,此错误是针对 WinCE 的,不会影响 Win32 设置.要获取您的操作系统版本,请从命令提示符运行ver"命令或运行 winver.exe.

For me this step was unsuccessful at first, since I lacked the environment variables OSVERSION and TARGETCPU. I set these to 5.1.2600 and x86 respectively. You may get complaint about OSVERSION being "insane", but look closer, this error is for WinCE and doesn't affect the Win32 setup. To get hold of your OS version, run the 'ver' command from a command prompt or run winver.exe.

3> nmake -f ms
t.mak (for static library)

3> nmake -f ms
tdll.mak (for DLL)

源代码现在可以编译了.在我的笔记本电脑上花了大约 5 分钟.

The source now compiles. Took approx 5 minutes on my laptop.

编译完成后,libs或二进制文件已经放入:

When compilation is completed, the libs or binaries have been placed in:

distroot/out32 - 用于静态库构建

distroot/out32dll - 用于 DLL 构建

distroot/out32dll - for DLL build

构建和链接

现在,回到 Visual Studio 并指出库和包含头文件的路径.包含文件位于 distroot/inc32/openssl.

Now, back to visual studio and point out the libs and include path for headers. The include files are located in distroot/inc32/openssl.

记得添加 libeay32.libssleay32.lib 作为链接器输入.

Remember to add libeay32.lib and ssleay32.lib as linker input.

重新构建 libcurl 项目.

Rebuild the libcurl project.

错误!

至少对我来说是这个版本的 OpenSSL.它抱怨 OpenSSL 标头之一中的 struct typedef.我找不到这方面的任何信息.经过一个小时的谷歌搜索,我打破了自己的原则并从 OpenSSL 标头中注释掉了 typedef,幸运的是 libcurl 没有使用该符号,因此它构建得很好.

Well at least for me with this version of OpenSSL. it complained about a struct typedef in one of the OpenSSL headers. I couldn't find any info on this. After an hour of googling I broke my own principle and commented out the typedef from the OpenSSL header, and luckily libcurl wasn't using that symbol so it built fine.

更新:正如 Jason 所指出的,这个问题似乎从 1.0.0a 版本开始消失了.

现在,要确认为 libcurl 启用 SSL 支持,请运行以下代码:

Now, for confirming that SSL support is enabled for libcurl, run the following code:

curl_version_info_data * vinfo = curl_version_info( CURLVERSION_NOW );
if( vinfo->features & CURL_VERSION_SSL )
    // SSL support enabled
else
    // No SSL

<小时>

就这么简单.


Simple as that.

这篇关于在 Windows 上构建支持 SSL 的 libcurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆