Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

c++ - 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

But I can't find curllib.lib in the folder I downloaded. And I am still getting errors: enter image description here

After searching the internet for more help. I now get these error messages. There appears to be a problem with linking to libcurl.lib?

enter image description here

This is what I have configured: enter image description here


enter image description here

Inside /lib I have libcurl.lib and libcurl.dll


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:

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

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

  2. Start a new project in Visual Studio. Go to Project|Project Properties|VC++ Directories|Include Directories| Add the path to the include directory inside the downloaded package. (C:LibCurlinclude)

  3. Next, go to Project|Project Properties|Linker|General|Additional Library Directories| Add the path to the lib directory. (Where curllib.dll is located)

  4. Then, go to Project|Project Properties|Linker|Input|Additional Dependencies| And add curllib.lib

  5. Now if you compile a test program, you will likely get the message saying libsasl.dll is missing. 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. OpenLDAP for Windows

This is the result of my test code from above: enter image description here

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A lot of these instructions are out of date because they recommend the win32-ssl-devel-msvc package for curl, which no longer exists.

The following instructions allow you to build libcurl using only:

  • Visual Studio 2013
  • curl generic source tarball (tested on curl 7.44.0).

A. Build libcurl static library

  1. Download the latest curl generic source from: http://curl.haxx.se/latest.cgi?curl=tar.gz
  2. Extract the source to a local directory (we'll be using C:libcurl)
  3. Open a command prompt
  4. "C:Program Files (x86)Microsoft Visual Studio 12.0VCinvcvars32.bat" To initialize your VC environment variables (adjust your VS 2013 installation directory as needed)
  5. cd C:libcurlwinbuild
  6. nmake /f Makefile.vc mode=static VC=12
  7. The build should appear in C:libcurluildslibcurl-vc12-x86-release-static-ipv6-sspi-winssl

B. Link Against libcurl in Visual Studio

  1. In Visual Studio, right click your project in Solution Explorer, then click "Properties"
  2. Configuration Properties > C/C++ > General > Additional Include Directories: add C:libcurluildslibcurl-vc12-x86-release-static-ipv6-sspi-winsslinclude
  3. Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions: add CURL_STATICLIB
  4. Configuration Properties > Linker > General > Additional Library Directories: add C:libcurluildslibcurl-vc12-x86-release-static-ipv6-sspi-winssllib
  5. Configuration Properties > Linker > Input > Additional Dependencies: add libcurl_a.lib

C. Call libcurl from Your Project

The following sample shows a call to 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!
"); 
    else fprintf(stderr, "Error calling curl_easy_init().
");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...