简体   繁体   English

让LibCurl与Visual Studio 2013一起使用

[英]Getting LibCurl to work with Visual Studio 2013

I am having trouble getting LibCurl to work with Visual Studio 2013. I downloaded the current version (curl-7.33.0) and tried following the instructions I found on this site: Using LibCurl with Visual 2010 我无法使LibCurl与Visual Studio 2013一起工作。我下载了当前版本(curl-7.33.0)并尝试按照我在此站点上找到的说明操作: 在Visual 2010中使用LibCurl

But I can't find curllib.lib in the folder I downloaded. 但我在我下载的文件夹中找不到curllib.lib And I am still getting errors: 我仍然得到错误: 在此输入图像描述

After searching the internet for more help. 在互联网上搜索更多帮助。 I now get these error messages. 我现在收到这些错误消息。 There appears to be a problem with linking to libcurl.lib? 链接到libcurl.lib似乎有问题?

在此输入图像描述

This is what I have configured: 这是我配置的: 在此输入图像描述


在此输入图像描述

Inside /lib I have libcurl.lib and libcurl.dll 在/ lib我有libcurl.liblibcurl.dll


UPDATE UPDATE

I downloaded this release for Win32 MSVC: http://curl.haxx.se/download.html#Win32 After adding the libcurl libraries and successfully compiling, I am now getting this error message: 我为Win32 MSVC下载了此版本: http//curl.haxx.se/download.html#Win32添加libcurl库并成功编译后,我现在收到此错误消息:

 The application was unable to start correctly (0xc000007b). Click OK to close the application.

Here is the sample code I am trying to run: 这是我尝试运行的示例代码:

#include <iostream>
#include <stdio.h> 
#include <curl/curl.h> 


int main(void)
{
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
        res = curl_easy_perform(curl);

        /* always cleanup */
        curl_easy_cleanup(curl);
    }
    return 0;
}

FINAL UPDATE 最终更新

I believe I have gotten LibCurl to work with Visual Studio 2013 now. 我相信我已经让LibCurl与Visual Studio 2013合作了。 Persistence ftw! 坚持不懈! Although, after spending hours trying to solve these error messages, I am a little hesitant at saying everything is working fine now. 虽然花了好几个小时试图解决这些错误信息后,我有点犹豫,说现在一切正常。 That is why I am putting a bounty on this question to get clear and concise instructions on getting LibCurl to work with Visual Studio 2013. 这就是为什么我要对这个问题给予一个赏金,以获得有关让LibCurl与Visual Studio 2013一起使用的简明扼要的说明。

This is what I did to get it to work: 这就是我为了让它发挥作用所做的事情:

  1. First, download the Win32 MSVC package here: http://curl.haxx.se/download.html#Win32 For these instructions sake, let's say you downloaded to C:\\LibCurl 首先,在这里下载Win32 MSVC软件包: http ://curl.haxx.se/download.html#Win32为了这些说明,让我们说你下载到C:\\ LibCurl

  2. Start a new project in Visual Studio. 在Visual Studio中启动一个新项目。 Go to Project|Project Properties|VC++ Directories|Include Directories| 转到项目|项目属性| VC ++目录|包含目录| Add the path to the include directory inside the downloaded package. 将路径添加到下载的包中的include目录。 (C:\\LibCurl\\include) (C:\\ libcurl中\\包括)

  3. Next, go to Project|Project Properties|Linker|General|Additional Library Directories| 接下来,转到项目|项目属性|链接器|常规|其他库目录| Add the path to the lib directory. 将路径添加到lib目录。 (Where curllib.dll is located) (curllib.dll所在的位置)

  4. Then, go to Project|Project Properties|Linker|Input|Additional Dependencies| 然后,转到Project | Project Properties | Linker | Input | Additional Dependencies | And add curllib.lib 并添加curllib.lib

  5. Now if you compile a test program, you will likely get the message saying libsasl.dll is missing. 现在,如果您编译测试程序,您可能会收到消息说libsasl.dll缺失。 You will need to download this file and put it in the same directory as your build. 您需要下载此文件并将其放在与构建相同的目录中。 I used 7-Zip to extract libsasl.dll from OpenLDAP for Windows . 我使用7-Zip从OpenLDAP for Windows中提取libsasl.dll OpenLDAP for Windows OpenLDAP for Windows

This is the result of my test code from above: 这是我上面的测试代码的结果: 在此输入图像描述

A lot of these instructions are out of date because they recommend the win32-ssl-devel-msvc package for curl, which no longer exists . 很多这些说明已经过时了,因为他们推荐使用win32-ssl-devel-msvc软件包, 它不再存在

The following instructions allow you to build libcurl using only : 以下说明允许您使用以下内容构建libcurl:

  • Visual Studio 2013 Visual Studio 2013
  • curl generic source tarball (tested on curl 7.44.0). curl generic source tarball(在curl 7.44.0上测试)。

A. Build libcurl static library A.构建libcurl静态库

  1. Download the latest curl generic source from: http://curl.haxx.se/latest.cgi?curl=tar.gz http://curl.haxx.se/latest.cgi?curl=tar.gz下载最新的curl 通用源代码
  2. Extract the source to a local directory (we'll be using C:\\libcurl ) 将源解压缩到本地目录(我们将使用C:\\libcurl
  3. Open a command prompt 打开命令提示符
  4. "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\vcvars32.bat" To initialize your VC environment variables (adjust your VS 2013 installation directory as needed) "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\vcvars32.bat"初始化VC环境变量(根据需要调整VS 2013安装目录)
  5. cd C:\\libcurl\\winbuild
  6. nmake /f Makefile.vc mode=static VC=12
  7. The build should appear in C:\\libcurl\\builds\\libcurl-vc12-x86-release-static-ipv6-sspi-winssl 构建应该出现在C:\\libcurl\\builds\\libcurl-vc12-x86-release-static-ipv6-sspi-winssl

B. Link Against libcurl in Visual Studio B.在Visual Studio中链接libcurl

  1. In Visual Studio, right click your project in Solution Explorer, then click "Properties" 在Visual Studio中,右键单击解决方案资源管理器中的项目,然后单击“属性”
  2. Configuration Properties > C/C++ > General > Additional Include Directories: add C:\\libcurl\\builds\\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\\include 配置属性> C / C ++>常规>其他包含目录:添加C:\\libcurl\\builds\\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\\include
  3. Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions: add CURL_STATICLIB 配置属性> C / C ++>预处理器>预处理器定义:添加CURL_STATICLIB
  4. Configuration Properties > Linker > General > Additional Library Directories: add C:\\libcurl\\builds\\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\\lib 配置属性>链接器>常规>其他库目录:添加C:\\libcurl\\builds\\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\\lib
  5. Configuration Properties > Linker > Input > Additional Dependencies: add libcurl_a.lib 配置属性>链接器>输入>附加依赖项:添加libcurl_a.lib

C. Call libcurl from Your Project C.从您的项目中调用libcurl

The following sample shows a call to libcurl: 以下示例显示了对libcurl的调用:

#include "stdafx.h"

#include <curl/curl.h>

void main(int argc, char* argv[])
{
    CURL *curl = curl_easy_init();
    if (curl) printf("curl_easy_init() succeeded!\n"); 
    else fprintf(stderr, "Error calling curl_easy_init().\n");
}

I would say that in a comment, but I am lacking in points. 我会在评论中说,但我缺乏积分。 You don't have to copy any .dll into your program run catalog. 您不必将任何.dll复制到程序运行目录中。 Go to Project | 转到项目| Properties | 属性| Configuration Properties and in line Envrionment write: PATH=$(ExecutablePath)$(LocalDebuggerEnvironment) . 配置属性和行管环境写: PATH=$(ExecutablePath)$(LocalDebuggerEnvironment)

From now on, all .dlls from any catalog you mention in Project|Project Properties|VC++ Directories|Binary should be usable without copying them. 从现在开始,您在项目|项目属性| VC ++目录|二进制文件中提及的任何目录中的所有.dll都应该可以使用而无需复制它们。

The rest is exactly as you written. 其余的与你所写的完全一样。

The easiest way to do this that I found is first make sure that nuget is installed. 我找到的最简单的方法是首先确保安装了nuget。

http://www.nuget.org/ http://www.nuget.org/

Then create your project. 然后创建您的项目。

Then go to http://www.nuget.org/packages/curl/ and follow the instructions which is to go the package manager console and type PM> Install-Package curl 然后转到http://www.nuget.org/packages/curl/并按照包管理器控制台的说明进行操作,然后键入PM> Install-Package curl

If you then look for the packages directory in your project directory, you will find the include files and the library files. 然后,如果您在项目目录中查找packages目录,则会找到包含文件和库文件。 Note that there is a version for Visual Studio 110, not 120, but because libcurl is a C library you can use it with Visual Studio 2013. Make sure the include directory and lib directory are specified under the Visual C++ directories in project properties. 请注意,Visual Studio 110有一个版本,而不是120,但由于libcurl是一个C库,因此可以将它与Visual Studio 2013一起使用。确保在项目属性中的Visual C ++目录下指定了include目录和lib目录。

Make sure you have the following files as addition input to the linker 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;附加输入libcurl.lib;libeay32.lib;ssleay32.lib;Ws2_32.lib;libssh2.lib;zlib.lib;wldap32.lib;

Another way to use curl/libcurl is build with CMake v2.8.12+ (assuming that git is already installed on your computer) 另一种使用curl / libcurl的方法是使用CMake v2.8.12 +构建(假设你的计算机上已经安装了git)

Open cmd window and change dir to appropriate folder 打开cmd窗口并将dir更改为适当的文件夹

git clone https://github.com/bagder/curl.git
mkdir msbuild
cd msbuild
cmake ..\curl -G"Visual Studio 12 Win64" -DCMAKE_INSTALL_PREFIX=C:\curl.vc12 -DCURL_STATICLIB=ON
< ... lots of output here ... >

Open generated CURL.sln in Visual studio and build it. 在Visual Studio中打开生成的CURL.sln并构建它。

CMake options I use in example 我在示例中使用的CMake选项

-G selects build generator. -G选择构建生成器。 In our case Visual Studio 2013 64 bit target 在我们的案例中,Visual Studio 2013 64位目标

-DCMAKE_INSTALL_PREFIX - provides root folder where targets should be installed -DCMAKE_INSTALL_PREFIX - 提供应安装目标的根文件夹

-DCURL_STATICLIB=ON - generates build for static library -DCURL_STATICLIB = ON - 为静态库生成构建

After building install target, your will find bin/include/lib folders in C:\\curl.vc12 构建安装目标后,您将在C:\\ curl.vc12中找到bin / include / lib文件夹

Provide those path to your solution and build your code with curl lib. 提供解决方案的路径并使用curl lib构建代码。

I tried to do it from scratch with VS2012 (I don't have 2013) and it works perfectly. 我试图从头开始使用VS2012(我没有2013),它完美无缺。

So, I'm not sure what your problem is, but: 所以,我不确定你的问题是什么,但是:

  • Make sure you download the right archive. 确保下载正确的存档。
  • Try to put the cURL folder on a path without space. 尝试将cURL文件夹放在没有空格的路径上。
  • If you know someone who use VS2012 or older, try your code with the same include and lib and see if it works. 如果您认识使用VS2012或更早版本的人,请使用相同的include和lib尝试您的代码,看看它是否有效。
  • Paste a minimal working example of your code so I can test it. 粘贴代码的最小工作示例,以便我可以测试它。

This is a bit late, but for those who still have problems, this method worked best for me: 这有点晚了,但对于那些仍然有问题的人来说,这种方法最适合我:

  1. Add VS to the system PATH: 将VS添加到系统路径:
    For example: C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin . 例如: C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin
  2. Download current curl-X.zip from http://curl.haxx.se/download.html and unzip. http://curl.haxx.se/download.html下载当前的curl-X.zip并解压缩。
  3. Open command line at curl-X/winbuild . curl-X/winbuild打开命令行。
  4. Call vcvars32.bat . 请致电vcvars32.bat
  5. Call nmake /f Makefile.vc mode=static VC=12 . 调用nmake /f Makefile.vc mode=static VC=12
  6. Goto curl-X/builds/libcurl-XXX . 转到curl-X/builds/libcurl-XXX

There you find the includes and a libcurl_a.lib . 在那里你找到了包含和libcurl_a.lib This lib works fine for me. 这个lib对我来说很好。
Remember to define -DCURL_STATICLIB when you compile your code with this lib. 在使用此lib编译代码时,请记住定义-DCURL_STATICLIB

For Visual Studio 2017, the steps in link worked for me. 对于Visual Studio 2017, 链接中的步骤对我有用。 In case the link expires or specifically for those who download the libcurl zip file instead of cloning from GitHub, I will note down the steps here. 如果链接过期或专门为那些下载libcurl zip文件而不是从GitHub克隆的人,我会记下这里的步骤。

  1. Set environment variables with “C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat” x64 . 使用“C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat” x64设置环境变量。 If the command is successful, you will see a message that says Environment initialized for 'x64' 如果命令成功,您将看到一条消息,其中显示Environment initialized for 'x64'

  2. Download and extract the compressed libcurl file from download libcurl . 下载libcurl下载并解压缩压缩的libcurl文件。 I used the .zip file. 我使用了.zip文件。

  3. cd into winbuild directory inside the extracted libcurl folder. cd进入winbuild压缩的libcurl文件夹中的winbuild目录。
  4. Run nmake /f Makefile.vc mode=dll MACHINE=x64 to build. 运行nmake /f Makefile.vc mode=dll MACHINE=x64来构建。 For more information on build options, please refer to BUILD.WINDOWS text file in winbuild folder. 有关编译选项的详细信息,请参阅BUILD.WINDOWS文本文件中winbuild文件夹。
  5. Go up one directory level and cd into builds folder to find the compiled files. 上去一级目录和cdbuilds文件夹中找到编译后的文件。

All the best! 祝一切顺利!

The problem is that the targets for the default VS2013 platform tools are not set in the NuGet packages . 问题是默认VS2013平台工具目标未在NuGet包中设置 This is why it works in VS2012 but not VS2013. 这就是为什么它适用于VS2012而不是VS2013。 I manually created replacement targets files. 我手动创建了替换目标文件。 Instructions and download: 说明和下载:

https://github.com/evoskuil/curl-nuget-targets https://github.com/evoskuil/curl-nuget-targets

Download the curl v7.37.0 source code and use the Visual Studio project files provided. 下载curl v7.37.0源代码并使用提供的Visual Studio项目文件。

I've spent the last few weeks polishing my own personal project files, that were based off the original VC6 files, and adding them to the repository. 我花了最近几周的时间来完善自己的个人项目文件,这些文件基于原始的VC6文件,并将它们添加到存储库中。

.dsw / .dsp (VC6), .sln / .vcproj (VC7, VC7.1, VC8 and VC9 as well as .sln / .vcxproj (VC10, VC11 and VC12) files are provided for both DLL and Static Library builds with support for OpenSSL and Windows SSPI / SChannel in both Win32 and x64 configurations. .dsw / .dsp(VC6),. sln / .vcproj(VC7,VC7.1,VC8和VC9以及.sln / .vcxproj(VC10,VC11和VC12)文件是为DLL和静态库构建提供的在Win32和x64配置中支持OpenSSL和Windows SSPI / SChannel。

I found an easy way to get it work in VC++ using the latest package. 我找到了一种简单的方法,可以使用最新的软件包在VC ++中使用它。 I basically followed the steps in Using libcurl in Visual Studio. 我基本上遵循了在Visual Studio中使用libcurl的步骤。 The libcurl and VC++ are very old in the instruction. libcurl和VC ++在指令中非常陈旧。

First download the ZIP file on download page https://curl.haxx.se/download.html The ZIP package is https://curl.haxx.se/download/curl-7.50.1.zip 首先在下载页面下载ZIP文件https://curl.haxx.se/download.html ZIP包是https://curl.haxx.se/download/curl-7.50.1.zip

Go to projects-> Windows\\VC10 (or your version of VC)\\lib\\libcurl.sln, open the project in VC++. 转到项目 - > Windows \\ VC10(或您的VC版本)\\ lib \\ libcurl.sln,在VC ++中打开项目。

Build the project in DLL Release. 在DLL Release中构建项目。 DLL debug doesn't work on my VC++. DLL调试不适用于我的VC ++。

Go to build\\Win32\\VC10\\DLL Release, you can find the lib and dll files generated from previous step. 转到build \\ Win32 \\ VC10 \\ DLL Release,你可以找到从上一步生成的lib和dll文件。

Create a folder new, with include and lib folders. 使用include和lib文件夹创建一个新文件夹。 Copy the libcurb.dll and libcurb.lib whatever is in the DLL Release folder to the new\\lib. 将libcurb.dll和libcurb.lib复制到DLL Release文件夹中的任何内容到新的\\ lib。 Copy everything in curl-7.50.1\\include to new\\include folder. 将curl-7.50.1 \\ include中的所有内容复制到新的\\ include文件夹中。

C++ Properties -> Configuration Properties -> VC++ Directories, add new\\include to Include Directories, new\\lib to Library Directories; C ++属性 - >配置属性 - > VC ++目录,添加新的\\ include到包含目录,将新的\\ lib添加到库目录; add new\\lib to Linker -> General -> Additional Library Directories, add libcurl.lib to Linker -> Input -> Additional Dependencies 将new \\ lib添加到Linker - > General - > Additional Library Directories,将libcurl.lib添加到Linker - > Input - > Additional Dependencies

It seems that I have to put the dll file under the same folder with executable file. 似乎我必须将dll文件放在与可执行文件相同的文件夹下。

It should work. 它应该工作。

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

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