gpt4 book ai didi

c++ - 如何构建 cURL 并在 Code::Blocks 项目中使用它(静态)

转载 作者:行者123 更新时间:2023-11-30 02:41:55 27 4
gpt4 key购买 nike

我知道有很多关于此的话题,但没有一个能帮助我解决我的问题。我想要的只是制作一个简单的 C++ 程序,它在 Code::Blocks 上使用 cURLstatic libcurl(没有 DLL 文件) - Windows 8。我花了大约 20 个小时来尝试这样做,但我发现的都是无用的东西和我不理解的东西。

http://curl.haxx.se/download.html 下载 curl-7.39.0.zip 并将其解压缩到我的 Code::Block 目录,我以管理员身份运行 VS2013 开发人员命令提示符 并输入以下内容:

cd C:\Program Files (x86)\CodeBlocks\curl-7.39.0\winbuild
nmake /f Makefile.vc mode=static vc=12 debug=no

第二个命令的输出是: http://pastebin.com/bwPqxp9V

然后我用 Main.cpp 创建了一个新的空 Code::Blocks 项目:

#include <curl/curl.h>
int main() { curl_global_cleanup(); }

Code::Blocks 中,我导航到 Project > Build Options
Compiler Settings > Defines 中,我添加了 CURL_STATICLIB
Linker Settings > Link Libraries 中,我添加了生成的(存在的).lib 文件的路径:

..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib

Linker Settings > Other Link Options中,我添加了-static
Search Directories > Compiler 中,我添加了:

..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\include

我可能编辑了一些其他的东西,但都不重要。
当我使用 GNU GCC Compiler 和以下命令构建时:

mingw32-g++.exe  -o Debug\MyTestProgram.exe Debug\Main.o  -static  "..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib"

我收到 80 条警告,类似于:

.drectve `/DEFAULTLIB:"MSVCRT" /DEFAULTLIB:"OLDNAMES" ' unrecognized

还有超过 50 个错误。我做错了什么,我该如何解决?
如果需要,请随时向我询问更多详情。

错误日志:

..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\easy.obj):(.text$mn+0x7)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\easy.obj):(.text$mn+0x44)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\easy.obj):(.text$mn+0x64)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x13b)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x151)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x10d)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x295)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x2ac)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x17b)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\multi.obj):(.text$mn+0x2ea)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\cookie.obj):(.text$mn+0x7)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\cookie.obj):(.text$mn+0x80)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\cookie.obj):(.text$mn+0x41d)||undefined reference to `_imp__strtoll'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\cookie.obj):(.text$mn+0x58f)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\cookie.obj):(.text$mn+0x754)||undefined reference to `_imp__strtoll'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\cookie.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\cookie.obj):(.text$mn+0x45)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\cookie.obj):(.text$mn+0x57)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\curl_sspi.obj):(.text$mn+0x7)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\curl_sspi.obj):(.text$mn+0xca)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\curl_sspi.obj):(.text$mn+0xfc)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\asyn-thread.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\asyn-thread.obj):(.text$mn+0x5a)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\asyn-thread.obj):(.text$mn+0x91)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\asyn-thread.obj):(.text$mn+0x12e)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\asyn-thread.obj):(.text$mn+0x198)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\asyn-thread.obj):(.text$mn+0x1ae)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\asyn-thread.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\asyn-thread.obj):(.text$mn+0xaa)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\hostip.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\hostip.obj):(.text$mn+0x88)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\hostip.obj):(.text$mn+0x7)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\hostip.obj):(.text$mn+0x178)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\hostip.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\hostip.obj):(.text$mn+0x42)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\hostip.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\hostip.obj):(.text$mn+0x7b)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\hostip.obj):(.text$mn+0x8e)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\url.obj):(.text$mn+0x7)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\url.obj):(.text$mn+0x12c)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\url.obj):(.text$mn+0x7)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\url.obj):(.text$mn+0xd5)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\url.obj):(.text$mn+0x115)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\url.obj):(.text$mn+0x4)||undefined reference to `__security_cookie'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\url.obj):(.text$mn+0xa4)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\url.obj):(.text$mn+0x1c6)||undefined reference to `@__security_check_cookie@4'|
..\..\..\..\Program Files (x86)\CodeBlocks\curl-7.39.0\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib(..\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl-obj-lib\url.obj):(.text$mn+0x216)||undefined reference to `@__security_check_cookie@4'|
||More errors follow but not being shown.|

最佳答案

介绍:

要在 Windows 上使用 gcc 构建 libcurl,您需要一个命令行工具。您可以使用 Git-Bash 或 MSYS。你的选择。


入门:

开始 MSYS 安装。选择您喜欢的任何文件夹进行安装。当命令行窗口弹出时,回答如下:

enter image description here


预设置:

现在您已经安装了一个命令行工具“make”并且与您的 gcc/g++/mingw 兼容。

在我们运行命令之前,您需要了解一些事情:

  • 如果使用 32 位 gcc/g++,则更改为:--build=i686-pc-mingw32

  • 如果使用 64 位 gcc/g++,则更改为:--build=x86_64-w64-mingw32

  • 如果使用 SSL,请将 --without-ssl 更改为 --with-ssl 并添加 -DOPENSSL_PATH=Path_To_Open_SSL_Here

  • 如果您需要指定 ZLIB 的特殊路径,请添加 -DZLIB_PATH=Path_To_ZLib_Here

  • 如果您想构建 STATIC,则使用 --disable-shared 否则不要使用它或使用 --enable-shared


配置:

打开 MSYS.bat 并运行以下命令(根据需要和如上所述进行修改):

$ cd "C:/Users/USERNAME/Desktop/curl-7.39.0"

$ ./configure --prefix=/usr/local --without-ssl --disable-shared --build=x86_64-w64-mingw32 CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"

它应该开始做一堆“检查”。这需要一段时间,所以去喝杯咖啡什么的。如果一切顺利且配置已完成,并且您已正确设置所有内容,那么您应该会看到以下内容:

enter image description here


构建和安装:

最后,运行以下命令:

$ make install-strip

它现在应该开始构建并将安装到(无论您的 MSYS 安装在哪里——我的是 C:/Msys):

 C:/Msys/1.0/local/bin
C:/Msys/1.0/local/include
C:/Msys/1.0/local/lib

这些位置应该包含您将 libcurl 与 gcc/g++/mingw 一起使用所需的所有文件。

如果一切顺利,它看起来像: enter image description here


可选:

  • 您可以在该位置链接到它们或移动它们。
  • 您可以将“include”、“lib”和“bin”中的文件分别复制到您的mingw安装文件夹中(include + curl-folder to include,bin to bin,lib + package-folder to lib)。

关于c++ - 如何构建 cURL 并在 Code::Blocks 项目中使用它(静态),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27608364/

27 4 0
文章推荐: java - 我无法将一个类扩展到另一个具有构造函数的类
文章推荐: java - 如何在java中将时间四舍五入到最接近的15分钟
文章推荐: List 内的 Java 过滤器映射