简体   繁体   English

使用Visual Studio 2013进行cURL

[英]cURL with Visual Studio 2013

So i have came along with cURL as a very nice library and working very fine in OSX. 所以我和cURL一起作为一个非常好的库而且在OSX中运行得非常好。 But on windows now i have got big troubles with getting ready with this library. 但是现在在Windows上我已经为这个库做好了准备。 I googled now for about 2 days and tried over a dozen (in detail) different ways to get this ready. 我现在用Google搜索了大约2天,并尝试了十几种(详细的)不同的方法来做好准备。 Without any success at all. 没有任何成功。

Here are some ways I basically tried: 以下是我基本上尝试过的一些方法:

  1. The direct Download : The problem here already starts with the right download. 直接下载 :这里的问题已经从正确的下载开始。 The official download page is pretty confusing, so i considered this "cURL Download Wizard" > "libcurl development" which gives me a version, that i should be able to include into any project. 官方下载页面相当令人困惑,所以我认为这个“cURL下载向导”>“libcurl开发”给了我一个版本,我应该能够包含在任何项目中。 But how exactly to include it? 但究竟要包括它呢? In ANY instructions out there it leads me to directories i dont even have. 在任何指示中,它引导我到我甚至没有的目录。 Almost always this "curllib.lib" is mentioned. 几乎总是提到这个“curllib.lib”。 I downloaded about 6 different versions on that downloadpage, in none of them there is this file. 我在该下载页面上下载了大约6个不同的版本,其中没有一个版本存在此文件。 (See for example this instruction) (参见例如说明)
  2. Git + CMake : As a solution on the aboves Link there is suggested to use git clone on this. Git + CMake :作为上述链接的解决方案,建议在此使用git clone。 I did all the instructions there and also get the Projects generated with just warnings. 我在那里做了所有的指示,并且只用警告生成了Project。 But here it says as well: 但这里也说:
    After building install target, your will find bin/include/lib folders in C:\\curl.vc12 构建安装目标后,您将在C:\\ curl.vc12中找到bin / include / lib文件夹
    Well, i did not really get his point of "build install target", i just build the entire project map as it comes. 好吧,我没有真正得到他的“构建安装目标”,我只是构建整个项目地图。 Compiles fine (115 succeeded, 0 failed, 2 skipped). 编译正常(115成功,0失败,2跳过)。 But now C:\\curl.vc12 is not there. 但现在C:\\ curl.vc12不在那里。 What do i have to pre-setup before compiling this? 在编译之前我需要预先设置什么?
  3. NuGet : The idea comes from the link in point (1) again, a different solution with NuGet. NuGet :这个想法再次来自第(1)点的链接,与NuGet的不同解决方案。
    With Successfully added 'curl 7.30.0.2' to test. Successfully added 'curl 7.30.0.2' to test. it also seemed nice, but compiling simple.c leads to a bunch of unresolved external symbol linker errors. 它看起来也不错,但编译simple.c会导致一堆unresolved external symbol链接器错误。 But a solution is provided: 但是提供了一个解决方案:
    Make sure the include directory and lib directory are specified under the Visual C++ directories in project properties. 确保在项目属性中的Visual C ++目录下指定了include目录和lib目录。
    So in Project > Properties > VC++ Properties > "Include Directories" and 所以在Project > Properties > VC++ Properties > "Include Directories"
    Project > Properties > VC++ Properties > "Library Directories"
    as well as in Project > C/C++ > General > "Additional Include Directories" and in Project > Linker > General > "Additional Library Directories" I desperately added the \\packages\\ path from my project folder. 以及在Project > C/C++ > General > "Additional Include Directories"Project > Linker > General > "Additional Library Directories"我拼命地从我的项目文件夹中添加了\\ packages \\ path。
    As mentioned in the instructions, I added libcurl.lib;libeay32.lib;ssleay32.lib;Ws2_32.lib;libssh2.lib;zlib.lib;wldap32.lib; 如说明书中所述,我添加了libcurl.lib;libeay32.lib;ssleay32.lib;Ws2_32.lib;libssh2.lib;zlib.lib;wldap32.lib; to Project > Linker > Input > "Additional Dependencies" . Project > Linker > Input > "Additional Dependencies"
    All that done, the unresolved external symbol errors are gone! 所有这一切, unresolved external symbol错误都消失了! Therefore I get just one error saying cannot open file 'libcurl.lib' . 因此我只得到一个错误,说cannot open file 'libcurl.lib' What can I do here? 我能在这做什么?

I am pretty new to all that. 我对这一切都很陌生。 But I am trying really hard now to get this finally to work. 但是我现在正在努力让这个最终发挥作用。 So what can I do? 那我该怎么办?
I work with Visual Studio 2013 Community Edition. 我使用Visual Studio 2013社区版。 The currently most recent version of cURL is 7.42.1 . 目前最新版本的cURL是7.42.1 Any help is highly welcome! 非常欢迎任何帮助!

Had problems myself, finally got it working now. 我自己有问题,现在终于搞定了。 I downloaded curl-7.42.1.zip from the official website . 我从官方网站上下载了curl-7.42.1.zip Within the archive you'll find the source code and winbuild/BUILD.WINDOWS.txt, which basically contains the instructions I followed. 在存档中,您将找到源代码和winbuild / BUILD.WINDOWS.txt,它基本上包含我遵循的说明。 I'll assume that it has been unzipped to C:\\curl-7.42.1. 我假设它已被解压缩到C:\\ curl-7.42.1。

Open the Visual Studio command prompt located at 打开位于的Visual Studio命令提示符

C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\Tools\\Shortcuts C:\\ Program Files(x86)\\ Microsoft Visual Studio 12.0 \\ Common7 \\ Tools \\ Shortcuts

This automatically sets the environment variables needed to use Visual Studio tools like the compiler. 这会自动设置使用Visual Studio工具(如编译器)所需的环境变量。 Then move to the winbuild directory and call 然后转到winbuild目录并调用

nmake /f Makefile.vc mode=dll nmake / f Makefile.vc mode = dll

as described in the text file I mentioned above. 如上面提到的文本文件中所述。

That will create the directory 那将创建目录

C:\\curl-7.42.1\\builds\\libcurl-vc-x86-release-dll-ipv6-sspi-winssl C:\\卷曲-7.42.1 \\建立\\ libcurl中,VC-x86的版本的DLL-IPv6的SSPI-winssl

containing libcurl.dll, libcurl.lib and the necessary header files. 包含libcurl.dll,libcurl.lib和必要的头文件。 Let's rename it to C:\\curl-7.42.1\\builds\\release :'D 让它重命名为C:\\curl-7.42.1\\builds\\release :'D

  1. Then open your project. 然后打开你的项目。
  2. Open your project's properties. 打开项目的属性。
  3. Make sure you choose Release as configuration (top left corner)! 确保选择Release as configuration(左上角)!
  4. Navigate to VC++ Directories > Include directories and add C:\\curl-7.42.1\\builds\\release\\include 导航到VC++ Directories > Include directories然后添加C:\\curl-7.42.1\\builds\\release\\include
  5. Add C:\\curl-7.42.1\\builds\\release\\lib to VC++ Directories > Library directories . C:\\curl-7.42.1\\builds\\release\\libVC++ Directories > Library directories
  6. Go to Linker > Input > Additional Dependencies and add libcurl.lib . 转到Linker > Input > Additional Dependencies并添加libcurl.lib
  7. Finally copy C:\\curl-7.42.1\\builds\\release\\bin\\libcurl.dll to your project folder. 最后将C:\\curl-7.42.1\\builds\\release\\bin\\libcurl.dll复制到项目文件夹中。

That should do the trick! 这应该够了吧! :D If you want to use cURL in debug mode, you can do almost the same, recompile using nmake /f Makefile.vc mode=dll debug=yes , go to your project's properties, add the newly created directory paths (changing libcurl.lib to libcurl_debug.lib) and you should be done. :D如果你想在调试模式下使用cURL,你可以做几乎相同,使用nmake /f Makefile.vc mode=dll debug=yes重新编译nmake /f Makefile.vc mode=dll debug=yes ,转到项目的属性,添加新创建的目录路径(更改libcurl。 lib到libcurl_debug.lib)你应该完成。

I had the same issue. 我遇到过同样的问题。 I downloaded the curl from https://github.com/curl/curl . 我从https://github.com/curl/curl下载了curl。 you can actually compile it directly with Visual Studio 2013 (but be careful with parameters setting: x64 with release). 您可以使用Visual Studio 2013直接编译它(但请注意参数设置:x64 with release)。 The major difference is that it gives you libcurl_imp.lib. 主要区别在于它为您提供了libcurl_imp.lib。 Then all you have to do is to set the environment variables as described above. 然后,您所要做的就是如上所述设置环境变量。 Just want to mention, you will have to use libcurl_imp.lib rather than libcurl.lib in the additional dependencies (I suspect this change is because of the new version of curl). 只是想提一下,你将不得不在其他依赖项中使用libcurl_imp.lib而不是libcurl.lib(我怀疑这个更改是因为curl的新版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM