52

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:\LibCurl\include)

  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

Preet Kukreti
  • 8,417
  • 28
  • 36
Quaxton Hale
  • 2,460
  • 5
  • 40
  • 71
  • 2
    I am so tired. If anyone cares to edit my instructions to make it clear, please do. I'm just happy to get libcurl to work. – Quaxton Hale Nov 25 '13 at 08:05
  • Thank you for posted final conclusion on how to get it work with Visual Studio 2013. :) – Mohd Shahril Jan 25 '14 at 16:22
  • The irony. I don't even use Windows anymore, at least not now. – Quaxton Hale Apr 13 '14 at 22:22
  • Looks like unbelievable, but I get this working at first install try! it doesn't happen too often. – The Mask Jun 05 '14 at 05:58
  • Thank you for sharing your solution. I downloaded "libsasl.dll" at this address instead: "http://dlldb.com/libsasl-dll/" so that I didn't have to install "OpenLDAP for Windows". – Léa Massiot Jun 22 '14 at 11:20
  • "libsasl.dll", "openldap.dll" and "curllib.dll" have to be put somewhere that the application can find it. For example in: "C:\Project\libcurl\VisualStudio\MyApplication\Debug\" – Léa Massiot Jun 22 '14 at 12:07
  • Thank you for the detailed guide! I saw that the latest version of msvc libcurl build wasn't available on the official website. So, the library I've found on the internet is on the link below. https://osdn.net/projects/sfnet_jcurltools/downloads/depending/libcurl-7.19.3-win32-ssl-msvc.7z/ – Walker Jul 01 '17 at 02:32

10 Answers10

72

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.0\VC\bin\vcvars32.bat" To initialize your VC environment variables (adjust your VS 2013 installation directory as needed)
  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

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:\libcurl\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\include
  3. Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions: add CURL_STATICLIB
  4. Configuration Properties > Linker > General > Additional Library Directories: add C:\libcurl\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib
  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!\n"); 
    else fprintf(stderr, "Error calling curl_easy_init().\n");
}
mtlynch
  • 3,403
  • 4
  • 31
  • 31
  • 4
    Finally got it working for visual studio 2015...thank you man I literally love you :) – Scdev Sep 20 '15 at 19:26
  • This should be chosen as the best answer, this also applies to VS2010 – avee Dec 15 '15 at 04:04
  • @mtlynch, how to build this for x64? Currently this builds for x86. – programmer Feb 13 '16 at 18:21
  • To link in the static C runtime (CRT) set the environment variable RTLIBCFG to static on the command line before building curl: Set RTLIBCFG=static – Helge Klein Mar 05 '16 at 01:22
  • Wow... It was not obvious. Where I could read, how to do things like that (B) in general case (other libs)? – re-gor Mar 19 '16 at 16:51
  • Thank you! This worked great for Visual Studio 2015. I'm new to C and Visual Studio and had big trouble understanding how to get libcurl to work for a simple project. This saved my day! – Olav Grønås Gjerde Mar 27 '16 at 16:29
  • Any idea how we can build it with ssh support? – Hamy May 21 '16 at 03:58
  • 5
    @programmer To build this for the x64 architecture you need to open a command prompt as stated and in step 4, execute the `vcvars64.bat` found in `C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64` (or equivalent). In step 6 you need to specify that you're targeting x64, as follows: `nmake /f Makefile.vc mode=static VC=12 MACHINE=x64`. Finally, if you've already accidentally built for the x64 architecture with the wrong (32-bit) tools, go in to the `/builds` folder in your libcurl folder, and delete the folders denoted with x64 – Gazoo May 24 '16 at 16:52
  • In case if you only need basic feature of the curl. type `nmake /f Makefile.vc mode=static enable_idn=no enable_sspi=no use_winssl=no enable_ipv6=no VC=12` – Hill Dec 03 '16 at 13:25
  • Ugh, no luck,. i've tried 4 diff builds. works on a standalone project but with integration: still getting unresolved :L (vs17) – Jamie Nicholl-Shelley Oct 30 '17 at 13:29
13

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. Go to Project | Properties | Configuration Properties and in line Envrionment write: 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.

The rest is exactly as you written.

Michał
  • 2,202
  • 2
  • 17
  • 33
13

The easiest way to do this that I found is first make sure that nuget is installed.

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

If you then look for the packages directory in your project directory, you will find the include files and the library files. 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.

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;

John Bandela
  • 2,416
  • 12
  • 19
  • 6
    The above package works great for VS 2010. It is not compatible with VS 2015 (VS 2015 uses toolset v140 and the package only supports v110 and v120). For VS 2015 use rmt_curl instead (https://www.nuget.org/packages/rmt_curl) – Josh Nov 23 '15 at 22:50
  • This should be marked the right answer also. It is by far the easiest. Only as Josh already mentioned us rmt_curl instead. – Gregor Jul 03 '17 at 07:59
  • `rmt_curl` didn't work on VS2017 for me. I had to change toolset to previous one. In **Project Properties** | **General** | **Platform Toolset** change it to _Visual Studio 2015 (v140) and now it works_. – DivineCoder Aug 09 '17 at 09:31
10

Another way to use curl/libcurl is build with CMake v2.8.12+ (assuming that git is already installed on your computer)

Open cmd window and change dir to appropriate folder

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.

CMake options I use in example

-G selects build generator. In our case Visual Studio 2013 64 bit target

-DCMAKE_INSTALL_PREFIX - provides root folder where targets should be installed

-DCURL_STATICLIB=ON - generates build for static library

After building install target, your will find bin/include/lib folders in C:\curl.vc12

Provide those path to your solution and build your code with curl lib.

Sergei Nikulov
  • 5,029
  • 23
  • 36
  • fyi: you don't need git installed, you can do this from a source download too. there's a gui for cmake also although it doesn't gain you too much :) – Caribou Dec 05 '13 at 13:09
5

I tried to do it from scratch with VS2012 (I don't have 2013) and it works perfectly.

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.
  • If you know someone who use VS2012 or older, try your code with the same include and lib and see if it works.
  • Paste a minimal working example of your code so I can test it.
Nil
  • 2,345
  • 1
  • 26
  • 33
4

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:
    For example: 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.
  3. Open command line at curl-X/winbuild.
  4. Call vcvars32.bat.
  5. Call nmake /f Makefile.vc mode=static VC=12.
  6. Goto curl-X/builds/libcurl-XXX.

There you find the includes and a libcurl_a.lib. This lib works fine for me.
Remember to define -DCURL_STATICLIB when you compile your code with this lib.

David
  • 208
  • 2
  • 5
  • with nmake what option can I use to build an x64 lib? – programmer Feb 13 '16 at 18:24
  • 1
    You can use `MACHINE=x64` – David Feb 14 '16 at 19:03
  • 1
    Thanks! It worked. But the sample C++ code compiles only when i set the run-time as "Multi-Threaded with DLL". I thought static build allow me to set run-time to "Multi-Threaded (/MT)". – programmer Feb 15 '16 at 14:02
  • 1
    Yes, this is correct. See this description, it also has a solution for it (See `BUILD.WINDOWS.txt`): `If you are using mode=static nmake will create and link to the static build of libcurl but *not* the static CRT. If you must you can force nmake to link in the static CRT by passing RTLIBCFG=static. Typically you shouldn't use that option, and nmake will default to the DLL CRT. RTLIBCFG is rarely used and therefore rarely tested.` – David Feb 17 '16 at 10:52
3

For Visual Studio 2017, the steps in link worked for me. 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.

  1. Set environment variables with “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'

  2. Download and extract the compressed libcurl file from download libcurl. I used the .zip file.

  3. cd into winbuild directory inside the extracted libcurl folder.
  4. Run nmake /f Makefile.vc mode=dll MACHINE=x64 to build. For more information on build options, please refer to BUILD.WINDOWS text file in winbuild folder.
  5. Go up one directory level and cd into builds folder to find the compiled files.

All the best!

kovac
  • 4,945
  • 9
  • 47
  • 90
  • 1
    Perfect! I can confirm this works with curl-7.61.1 using VS2017 Build Tools and VS2017 Community. – d3dave Sep 24 '18 at 17:04
2

The problem is that the targets for the default VS2013 platform tools are not set in the NuGet packages. This is why it works in VS2012 but not VS2013. I manually created replacement targets files. Instructions and download:

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

evoskuil
  • 1,011
  • 1
  • 7
  • 13
2

Download the curl v7.37.0 source code and use the Visual Studio project files provided.

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.

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

Jamal
  • 763
  • 7
  • 22
  • 32
2

I found an easy way to get it work in VC++ using the latest package. I basically followed the steps in Using libcurl in Visual Studio. The libcurl and VC++ are very old in the instruction.

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

Go to projects-> Windows\VC10 (or your version of VC)\lib\libcurl.sln, open the project in VC++.

Build the project in DLL Release. DLL debug doesn't work on my VC++.

Go to build\Win32\VC10\DLL Release, you can find the lib and dll files generated from previous step.

Create a folder new, with include and lib folders. Copy the libcurb.dll and libcurb.lib whatever is in the DLL Release folder to the new\lib. Copy everything in curl-7.50.1\include to new\include folder.

C++ Properties -> Configuration Properties -> VC++ Directories, add new\include to Include Directories, new\lib to Library Directories; add new\lib to Linker -> General -> Additional Library Directories, add libcurl.lib to Linker -> Input -> Additional Dependencies

It seems that I have to put the dll file under the same folder with executable file.

It should work.

Daisy
  • 21
  • 1
  • 4