在 Windows 上构建支持 SSL 的 libcurl

发布于 2024-07-07 00:07:01 字数 124 浏览 8 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

夏末染殇 2024-07-14 00:07:18

响应和/或补充上述内容的一些注释..

首先,如果您不想搞乱 ActivePerl,Strawberry Perl 非常棒,并且非常适合此目的。

其次,如果可能的话,我建议不要使用 do_ms.bat,因为根据 INSTALL.W32,

这是值得做的,因为它会
导致更快的代码:例如它
通常会导致 2 次
RSA 例程中的加速。

另外,构建 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,

This is worth doing because it will
result in faster code: for example it
will typically result in a 2 times
speedup in the RSA routines.

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.

情丝乱 2024-07-14 00:07:18

我为 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

羞稚 2024-07-14 00:07:15
\ fatal error C1083: Cannot open include
file: 'stdlib.h': No such file or directory
NMAKE: fatal error U1077::return code 

该错误可以通过在 Visual Studio 中执行 vcvarsall.bat 来解决。

\ fatal error C1083: Cannot open include
file: 'stdlib.h': No such file or directory
NMAKE: fatal error U1077::return code 

That error can be solved by executing vcvarsall.bat in Visual Studio.

烟火散人牵绊 2024-07-14 00:07:13

如果您使用 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.

在巴黎塔顶看东京樱花 2024-07-14 00:07:11

如何在 Windows 上使用 OpenSSL(SSL 支持)构建 libcurl C/C++

  1. 安装 libcurl
  2. 安装 OpenSSl
  3. 使用 OpenSSL 构建 libcurl

安装 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 文件替换为以下内容:

ws2_32.lib
wldap32.lib
openssl.lib
libssl.lib
libcrypto.lib

应用并关闭属性窗口。

仍然选择 DLL Debug - DLL OpenSSL 构建配置,转到 Build -> 构建解决方案

从 OpenSSL bin 目录复制两个 dll 文件 libcrypto-1_1.dlllibssl-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

  1. Install libcurl
  2. Install OpenSSl
  3. Build libcurl with OpenSSL

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 to DLL Debug - DLL OpenSSL.

In the Solution Explorer, right click the project curl and go to Properties.

Under Linker -> General modify Additional Library Directories and add the path to your OpenSSL directory + \lib. In my case, this is C:\OpenSSL-Win32\lib.

Apply and close the properties window.

Right click the project libcurl and do the same as the previous step, add OpenSSL directory + \lib to Additional Library Directories under Linker -> General.

Under C/C++ -> General, add C:\OpenSSL-Win32\include to the Additional Include Directories.

Finally go to Linker -> Input and modify Additional Dependencies. Replace all the lib files to the following:

ws2_32.lib
wldap32.lib
openssl.lib
libssl.lib
libcrypto.lib

Apply and close the properties window.

With the DLL Debug - DLL OpenSSL build configuration still selected, go to Build -> Build Solution.

Copy the two dll files libcrypto-1_1.dll and libssl-1_1.dll from the OpenSSL bin directory (C:\OpenSSL-Win32\bin) to the just created build directory curl-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.

破晓 2024-07-14 00:07:11

就我而言,遵循curl README 文件就足够了。
我的配置如下:

  • Visual Studio 2015 (VC14)
  • 静态库
  • Win64
  • curl 版本 7.57.0
  • OpenSSL 1.0.2

libCurl 编译

  1. 在那里下载 libcurl 源: https://curl.haxx.se/download.html
  2. 解压文件并进入文件夹 curl-7.57.0\projects
  3. 打开 README文件并按照说明进行操作,这导致我执行以下操作:
    • 已下载OpenSSL
    • 解压它并将其重命名为openssl将其放在curl文件夹旁边,这很重要,因为您将打开希望在那里找到openssl的VS项目。
    • 安装Perl
    • 执行实用程序build-openssl.bat来执行openSSL的编译。 根据我的设置,结果如下:
      .\build-openssl.bat vc14 x64 版本 ..\..\openssl\
      只需运行 .\build-openssl.bat -help 即可了解有关参数的更多信息。
      之后,您可以看到 OpenSSL 已编译,因为您在此处获得了一个新文件夹:openssl\build\Win64
  4. 打开 Visual Studio 项目 curl-7.57.0\projects\Windows\VC14\curl -all.sln
  5. 确保将 Visual Studio 项目设置为您需要的构建配置(在我的例子中为 LIB Release - LIB OpenSSL
  6. 构建所有
  7. 库位于 curl -7.57.0\build\Win64\VC14\LIB 发布 - LIB OpenSSL\libcurl.lib

备注

  • 不要忘记在自己的项目中定义 CURL_STATICLIB 预处理器
  • 使用静态库,您可以必须链接到 libcurl 的依赖项,请参阅此答案
  • 您可能不想依赖 LDAP,在这种情况下,您可以在编译 libcurl 之前通过设置预处理器 CURL_DISABLE_LDAP 来禁用它。

In my case follow the curl README file was enough.
My configuration is the following:

  • Visual Studio 2015 (VC14)
  • Static library
  • Win64
  • curl version 7.57.0
  • OpenSSL 1.0.2

Compilation of libCurl

  1. Download libcurl source there: https://curl.haxx.se/download.html
  2. Uncompress the file and go to the folder curl-7.57.0\projects
  3. Open the README file and follow the instructions, this lead me to do the following:
    • Downloaded OpenSSL
    • Extract it and rename it to openssl, put it aside the curl folder, this is important as you'll open the VS project that expect to find openssl there.
    • Install Perl
    • Execute the utility 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
  4. Open the Visual Studio project curl-7.57.0\projects\Windows\VC14\curl-all.sln
  5. Be sure to set the visual studio project to the build configuration you need (LIB Release - LIB OpenSSL in my case)
  6. Build all
  7. The library is located at curl-7.57.0\build\Win64\VC14\LIB Release - LIB OpenSSL\libcurl.lib

Remarks

  • Don't forget to define the CURL_STATICLIB preprocessor in your own project
  • With static library, you will have to links with the dependencies of libcurl, see this answer
  • You might not want to depend on LDAP, in that case you can disable it by setting the preprocessor CURL_DISABLE_LDAP before you compile libcurl.
夕色琉璃 2024-07-14 00:07:09

当使用 Visual Studio 2010 在 Windows 上编译 OpenSSL 1.0.0 时,最终抛出了 0x2 错误:

NMAKE:致命错误 U1077:“C:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\BIN\cl.EXE"' : 返回代码 '0x2'

停止。

看来这个错误会因为perl配置文件中的一个标志,即-WX而抛出。
正如 MSDN 文档所述:

将所有编译器警告视为错误。 对于一个新项目,最好在所有编译中使用/WX; 解决所有警告将确保尽可能减少难以发现的代码缺陷。

删除配置文件中的 -WX 并重新输入所述命令 这里它构建良好并通过了所有测试。

When compiling OpenSSL 1.0.0 on Windows with Visual Studio 2010, it eventually threw a 0x2 error:

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\BIN\cl.EXE"' : return code '0x2'

Stop.

It seems that this error will be thrown because of a flag in the perl Configure file, namely -WX.
As the MSDN documentation states:

Treats all compiler warnings as errors. For a new project, it may be best to use /WX in all compilations; resolving all warnings will ensure the fewest possible hard-to-find code defects.

After removing the -WX occurrences in the Configure file and re-entering the commands stated here it built fine and passed all tests.

旧人 2024-07-14 00:07:08

根据 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.

遗忘曾经 2024-07-14 00:07:05

也许这不是任何人都在寻找的答案,但我只是从 此链接位于 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.

忘你却要生生世世 2024-07-14 00:07:04

这个答案已经过时了。 请参阅此处的实际指南 https://curl.se/docs/install.htmlcmake 也可用。


好吧,既然这篇文章很失败,我就得自己深入研究一下了。

另请查看其他答案和评论,以获取有关其他版本等的其他信息。

编辑:自从我发布此问题以来,似乎已经提供了现成的二进制文件来自curl主页。 查看James 的回答

所以这里是:

预处理器

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

USE_SSLEAY
USE_OPENSSL

(libcurl 使用 OpenSSL 来支持 SSL)

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

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

编译 OpenSSL 二进制文件

我下载了 OpenSSL 0.9.8 源代码分发版并将其解压。

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

我在构建时遇到了一些问题,这可能不适用于所有系统,但我会在这里介绍一下,以防有人遇到同样的情况。

根据 INSTALL.W32:

运行以下命令行任务,并将当前目录设置为源分发根目录:(

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

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

2> ms\do_ms

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

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

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

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

编译完成后,库或二进制文件已放置在:

distroot/out32 - 用于静态库构建

distroot/out32dll - 用于 DLL 构建

构建和链接

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

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

重建 libcurl 项目。

错误!

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

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

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

curl_version_info_data * vinfo = curl_version_info( CURLVERSION_NOW );
if( vinfo->features & CURL_VERSION_SSL )
    // SSL support enabled
else
    // No 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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文