在 Windows 上构建支持 SSL 的 libcurl
我在 Win32 C++ 应用程序中使用 libcurl。
我已将 curllib.vcproj 项目添加到我的解决方案中,并将其他项目设置为依赖于它。
如何在启用 SSL 支持的情况下构建它?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
响应和/或补充上述内容的一些注释..
首先,如果您不想搞乱 ActivePerl,Strawberry Perl 非常棒,并且非常适合此目的。
其次,如果可能的话,我建议不要使用 do_ms.bat,因为根据 INSTALL.W32,
另外,构建 OpenSSL 的 0.9.8l (L) 是一场噩梦,所以我最终放弃并恢复到 0.9.8k,它使用 libcurl 1.9 构建并(静态)链接,而无需问题。
Couple of notes in response to and/or in addition to the above..
First, if you don't want to mess with ActivePerl, Strawberry Perl is terrific and worked perfectly for this.
Second, in lieu of using do_ms.bat, I would recommend preferring do_masm if possible since, according to INSTALL.W32,
Also, build 0.9.8l (L) of OpenSSL was a nightmare so I eventually gave up and reverted to 0.9.8k which built and linked (statically) with libcurl 1.9 without issue.
我为 windows 7 rc7100 做了“do_nt.bat”
不要忘记“nmake -f ms\nt.mak install”正确复制标题
谢谢这确实有很大帮助
i did "do_nt.bat" for windows 7 rc7100
don't forget "nmake -f ms\nt.mak install" to copy the headers correctly
thanks this did help a lot
该错误可以通过在 Visual Studio 中执行 vcvarsall.bat 来解决。
That error can be solved by executing vcvarsall.bat in Visual Studio.
如果您使用 Visual Studio IDE 进行构建并收到 58 个奇怪的警告,例如
“不一致的 dll 链接curl_global_init/curl_msnprintf/...”,
您应该将 CURL_STATICLIB 添加到预处理器定义中。
因此整个定义行应如下所示:
USE_SSLEAY;USE_OPENSSL;CURL_STATICLIB。
这样所有的警告都会消失。
有些人会忽略警告并继续使用库,但随后会得到相应的*错误*,如curl_global_init/curl_msnprintf。 这可能很烦人。
希望它可以帮助别人。
If you build with Visual Studio IDE and get 58 odd warnings as the likes of
"inconsistent dll linkage curl_global_init / curl_msnprintf /..."
you should add CURL_STATICLIB to the preproccessor definitions.
so the entire definition line should look like:
USE_SSLEAY;USE_OPENSSL;CURL_STATICLIB.
With this all the warning will disappear.
Some would ignore the warnings and go on using the libs, but then will get corresponding *error*s as the likes of curl_global_init / curl_msnprintf. It can be very annoying.
Hope it can help somebody.
如何在 Windows 上使用 OpenSSL(SSL 支持)构建 libcurl C/C++
安装 libcurl
转至 libcurl下载页面并下载Source Archives下的ZIP文件。 在我的例子中,它被称为
curl-7.58.0。 zip
解压存档并使用 Visual Studio 打开
projects/Windows/VC15/curl_all.sln
。安装 OpenSSL
下载 OpenSSL 的 Windows 二进制文件。 就我而言,我下载了 Windows 安装程序文件
Win32 OpenSSL v1.1.0g
来自 Shining Light Productions 发行版。我的安装文件夹是
C:\OpenSSL-Win32
。使用 OpenSSL 构建 libcurl
在
curl_all.sln
Visual Studio 解决方案文件中,更改构建DLL 调试 - DLL OpenSSL
的配置。在解决方案资源管理器中,右键单击项目
curl
并转到“属性”。在
链接器 -> 下 常规
修改其他库目录
并添加OpenSSL目录+\lib
的路径。 就我而言,这是C:\OpenSSL-Win32\lib
。应用并关闭属性窗口。
右键项目
libcurl
,与上一步相同,将OpenSSL目录+\lib
添加到Linker下的
。Additional Library Directoryies
-> 一般在
C/C++ -> 下 常规
,将C:\OpenSSL-Win32\include
添加到其他包含目录
。最后进入
Linker -> 输入
并修改附加依赖项
。 将所有 lib 文件替换为以下内容:应用并关闭属性窗口。
仍然选择
DLL Debug - DLL OpenSSL
构建配置,转到Build -> 构建解决方案
。从 OpenSSL bin 目录复制两个 dll 文件
libcrypto-1_1.dll
和libssl-1_1.dll
(C:\OpenSSL-Win32\bin
)到刚刚创建的构建目录curl-7.58.0\build\Win32\VC15\DLL Debug - DLL OpenSSL
。验证构建
在构建目录中,运行
curld.exe
。 如果它运行时没有错误(缺少 dll 等),那么您的构建成功。How to build libcurl C/C++ with OpenSSL (SSL support) on Windows
Installing libcurl
Go to the download page of libcurl and donwnload the ZIP file under Source Archives. In my case it is called
curl-7.58.0.zip
Extract the archive and open
projects/Windows/VC15/curl_all.sln
with Visual Studio.Installing OpenSSL
Download the windows binary of OpenSSL. In my case, I downloaded the windows installer file
Win32 OpenSSL v1.1.0g
from the Shining Light Productions distribution.The installation folder for me is
C:\OpenSSL-Win32
.Building libcurl with OpenSSL
In the
curl_all.sln
Visual Studio solution file, change the build configuration toDLL Debug - DLL OpenSSL
.In the Solution Explorer, right click the project
curl
and go to Properties.Under
Linker -> General
modifyAdditional Library Directories
and add the path to yourOpenSSL directory + \lib
. In my case, this isC:\OpenSSL-Win32\lib
.Apply and close the properties window.
Right click the project
libcurl
and do the same as the previous step, addOpenSSL directory + \lib
toAdditional Library Directories
underLinker -> General
.Under
C/C++ -> General
, addC:\OpenSSL-Win32\include
to theAdditional Include Directories
.Finally go to
Linker -> Input
and modifyAdditional Dependencies
. Replace all the lib files to the following:Apply and close the properties window.
With the
DLL Debug - DLL OpenSSL
build configuration still selected, go toBuild -> Build Solution
.Copy the two dll files
libcrypto-1_1.dll
andlibssl-1_1.dll
from the OpenSSL bin directory (C:\OpenSSL-Win32\bin
) to the just created build directorycurl-7.58.0\build\Win32\VC15\DLL Debug - DLL OpenSSL
.Validating Build
Inside the build directory, run
curld.exe
. If it runs with no errors (missing dll, etc.) then your build was successful.就我而言,遵循curl README 文件就足够了。
我的配置如下:
libCurl 编译
curl-7.57.0\projects
openssl
,将其放在curl文件夹旁边,这很重要,因为您将打开希望在那里找到openssl的VS项目。build-openssl.bat
来执行openSSL的编译。 根据我的设置,结果如下:.\build-openssl.bat vc14 x64 版本 ..\..\openssl\
只需运行
.\build-openssl.bat -help
即可了解有关参数的更多信息。之后,您可以看到 OpenSSL 已编译,因为您在此处获得了一个新文件夹:
openssl\build\Win64
curl-7.57.0\projects\Windows\VC14\curl -all.sln
LIB Release - LIB OpenSSL
)curl -7.57.0\build\Win64\VC14\LIB 发布 - LIB OpenSSL\libcurl.lib
备注
CURL_STATICLIB
预处理器CURL_DISABLE_LDAP
来禁用它。In my case follow the curl README file was enough.
My configuration is the following:
Compilation of libCurl
curl-7.57.0\projects
openssl
, put it aside the curl folder, this is important as you'll open the VS project that expect to find openssl there.build-openssl.bat
to perform the compilation of openSSL. With my settings this became the following:.\build-openssl.bat vc14 x64 release ..\..\openssl\
just runs
.\build-openssl.bat -help
to know more about the parameters.After that you can see OpenSSL has been compiled as you got a new folder here:
openssl\build\Win64
curl-7.57.0\projects\Windows\VC14\curl-all.sln
LIB Release - LIB OpenSSL
in my case)curl-7.57.0\build\Win64\VC14\LIB Release - LIB OpenSSL\libcurl.lib
Remarks
CURL_STATICLIB
preprocessor in your own projectCURL_DISABLE_LDAP
before you compile libcurl.当使用 Visual Studio 2010 在 Windows 上编译 OpenSSL 1.0.0 时,最终抛出了 0x2 错误:
看来这个错误会因为perl配置文件中的一个标志,即-WX而抛出。
正如 MSDN 文档所述:
删除配置文件中的 -WX 并重新输入所述命令 这里它构建良好并通过了所有测试。
When compiling OpenSSL 1.0.0 on Windows with Visual Studio 2010, it eventually threw a 0x2 error:
It seems that this error will be thrown because of a flag in the perl Configure file, namely -WX.
As the MSDN documentation states:
After removing the -WX occurrences in the Configure file and re-entering the commands stated here it built fine and passed all tests.
根据 Robert Oschler 的建议,以下是我对问题的评论作为答案:
您可以使用预处理器符号:USE_WINDOWS_SSPI 和 USE_SCHANNEL 而不是 OpenSSL 来构建最新的 libcurl (2012),并为 Windows 提供本机 SSL 支持。
Following Robert Oschler's advice, here is my comment on the question as answer :
You can build recent libcurl (2012) with native SSL support for windows using the preprocessor symbols: USE_WINDOWS_SSPI and USE_SCHANNEL instead of the OpenSSL ones.
也许这不是任何人都在寻找的答案,但我只是从 此链接位于 http://curl.haxx.se/download.html
我运行了shakin提供的测试,
if( vinfo->features & CURL_VERSION_SSL )
被证明是真的。Maybe this isn't the answer anyone is looking for, but I simply just downloaded the precompiled DLLs from this link found at http://curl.haxx.se/download.html
I ran the test that sharkin provided, and
if( vinfo->features & CURL_VERSION_SSL )
proved to be true.这个答案已经过时了。 请参阅此处的实际指南 https://curl.se/docs/install.html。
cmake
也可用。好吧,既然这篇文章很失败,我就得自己深入研究一下了。
另请查看其他答案和评论,以获取有关其他版本等的其他信息。
编辑:自从我发布此问题以来,似乎已经提供了现成的二进制文件来自curl主页。 查看James 的回答。
所以这里是:
预处理器
需要将以下两个符号提供给预处理器,以便为 libcurl 启用 SSL:
(libcurl 使用 OpenSSL 来支持 SSL)
或者可以将这些符号直接添加到 libcurl 中名为 setup.h 的文件中,但我不太乐意修改第 3 方发行版中的代码,除非我真的必须这样做。
重建 libcurl 库,我现在收到一些有关未找到 OpenSSL 包含文件的错误。 当然,因为我还没有正确设置 OpenSSL 发行版。
编译 OpenSSL 二进制文件
我下载了 OpenSSL 0.9.8 源代码分发版并将其解压。
在源代码分发的根目录中有一个名为 INSTALL.W32 的文件,它描述了如何编译 OpenSSL 二进制文件。 构建链需要 perl,因此我安装了最新版本的 ActivePerl。
我在构建时遇到了一些问题,这可能不适用于所有系统,但我会在这里介绍一下,以防有人遇到同样的情况。
根据 INSTALL.W32:
运行以下命令行任务,并将当前目录设置为源分发根目录:(
其中“c:/some/openssl/dir”应替换为应安装 OpenSSL 的目录。不要使用空格在这种情况下,进一步的编译将会失败)
对我来说,这一步一开始是不成功的,因为我缺少环境变量 OSVERSION 和 TARGETCPU。 我将它们分别设置为 5.1.2600 和 x86。 您可能会抱怨 OSVERSION 太“疯狂”,但仔细一看,这个错误是针对 WinCE 的,不会影响 Win32 设置。 要了解您的操作系统版本,请从命令提示符运行“ver”命令或运行 winver.exe。
或
源代码现在可以编译。 在我的笔记本电脑上花了大约 5 分钟。
编译完成后,库或二进制文件已放置在:
distroot/out32 - 用于静态库构建
或
distroot/out32dll - 用于 DLL 构建
构建和链接
现在,返回 Visual Studio 并指出库和标头的包含路径。 包含文件位于 distroot/inc32/openssl 中。
请记住添加 libeay32.lib 和 ssleay32.lib 作为链接器输入。
重建 libcurl 项目。
错误!
至少对我来说这个版本的 OpenSSL 是这样。
它抱怨 OpenSSL 标头之一中存在 struct typedef。 我找不到任何这方面的信息。 经过一个小时的谷歌搜索后,我打破了自己的原则,从 OpenSSL 标头中注释掉了 typedef,幸运的是 libcurl 没有使用该符号,因此它构建得很好。
更新:正如 Jason 所指出的,这个问题似乎从 1.0.0a 版本开始就消失了。
现在,为了确认 libcurl 启用了 SSL 支持,请运行以下代码:
就这么简单。
This answer is outdated. See the actual guide here https://curl.se/docs/install.html.
cmake
is also available.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:
(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:
(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)
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.
or
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:
Simple as that.