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

时间:2014-12-22 18:26:36

标签: c++ curl libcurl

我知道有很多这方面的话题,但没有一个能帮助我解决我的问题。我想要的是在 Code :: Blocks上创建一个简单的 C ++ 程序,该程序使用 cURL 静态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 中,我导航到项目&gt;构建选项
编译器设置&gt;定义,我添加了CURL_STATICLIB
链接器设置&gt;链接库,我添加了生成的.lib文件的路径(存在):

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

链接器设置&gt;其他链接选项,我添加了-static
搜索目录&gt;编译器,我补充道:

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

我可能已经编辑了其他一些东西,但没什么重要的 当我使用 GNU GCC编译器使用以下命令构建时:

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

1 个答案:

答案 0 :(得分:3)

说明:

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


入门:

启动MSYS安装。选择您喜欢的任何文件夹进行安装。弹出命令行窗口时,按如下方式回答:

enter image description here


PRE-SETUP:

现在你有了一个命令行工具&#34; make&#34;安装并与您的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"

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

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


OPTIONAL:

  • 您可以在该位置链接到它们或移动它们。
  • 您可以复制&#34;包含&#34;,&#34; lib&#34;和&#34; bin&#34;分别进入你的mingw安装文件夹(包括+ curl-folder to include,bin to bin,lib + package-folder to lib)。