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

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

问题描述

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



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



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

解决方案

那么,因为这个职位失败了,我不得不自己挖掘这件事。



此外,请查看其他答案和评论,了解其他版本的其他信息。 b
$ b

编辑:自从我发布了这个Q,似乎是从卷曲主页提供的现成的二进制文件。请查看詹姆斯的回答



所以这里:



-



预处理程序



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

  USE_SSLEAY 
USE_OPENSSL

libcurl使用OpenSSL的SSL支持)



或者,符号可以直接添加到libcurl中的一个名为setup.h的文件,但我不太乐意修改代码



重建libcurl库,我现在得到一些关于OpenSSL包含文件未找到的错误。自然,因为我尚未正确设置OpenSSL分发。



编译OpenSSL二进制文件



我下载了OpenSSL 0.9.8源代码并将其解压缩。



在源代码分发的根目录中有一个文件INSTALL.W32,编译OpenSSL二进制文件。生成链需要perl,所以我安装了最新版本的ActivePerl。



我有一些麻烦的生成,这可能不适用于所有的系统,



根据INSTALL.W32:



运行在当前目录设置为源分发根目录的命令行任务之后:

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

:/ some / openssl / dir应该由安装OpenSSL的dir替换,不要在这个路径中使用空格,否则编译会失败)

  2> ms\do_ms 

对我来说,这一步首先不成功,因为我缺少环境变量OSVERSION TARGETCPU。我将它们分别设置为 5.1.2600 x86 。您可能会收到投诉OSVERSION是疯狂,但看起来更接近,这个错误是为WinCE和不会影响Win32安装程序。要获取您的操作系统版本,请从命令提示符处运行'ver'命令或运行winver.exe。

  3& nmake -f ms\\\
t.mak(对于静态库)

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

现在编译源。



编译完成后,libs或二进制文件放在:



distroot / out32 - 用于静态库建立





> distroot / out32dll - 用于DLL构建



构建和链接



现在,回到visual studio并指出libs和包含头的路径。 include文件位于 distroot / inc32 / openssl 中。



请记住添加 libeay32.lib > ssleay32.lib 作为链接器输入。



重建libcurl项目。



错误!



至少对于我这个版本的OpenSSL。
它抱怨一个结构typedef在其中一个OpenSSL头。我找不到任何信息。经过一个小时的谷歌搜索后,我打破了自己的原则,并从OpenSSL标题注释掉typedef,幸运的是libcurl没有使用该符号,所以它建好了。



更新:正如Jason所指出的,这个问题似乎在版本1.0.0a中已经消失。

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

  curl_version_info_data * vinfo = curl_version_info(CURLVERSION_NOW); 
if(vinfo-> features& CURL_VERSION_SSL)
//启用SSL支持
else
//无SSL
pre>




很简单。


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

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

How do I build it with SSL support enabled?

解决方案

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

Also check out the other answers and comments for additional info regarding other versions etc.

EDIT: Since I posted this Q there seems to be ready-built binaries made available from the curl homepage. Check out James' answer.

So here goes:

-

Preprocessor

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

USE_SSLEAY
USE_OPENSSL

(libcurl uses OpenSSL for SSL support)

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.

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.

Compiling OpenSSL binaries

I downloaded the OpenSSL 0.9.8 source distribution and unpacked it.

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.

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

(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> ms\do_ms

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\nt.mak (for static library)

or

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

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

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

distroot/out32 - for static library build

or

distroot/out32dll - for DLL build

Building and linking

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

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

Rebuild the libcurl project.

Error!

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.

Update: As pointed out by Jason, this issue seems to have dissapeared as of version 1.0.0a.

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天全站免登陆