libcurl on Windows with Visual Studio 2005

Jeff Mancuso July 27th, 2007

Developing on Windows can be a real pain. I spent a few hours looking around for an easy way to perform simple HTTP GET calls inside vanilla win32 code. What a pain. WinINet is a disaster and WinHTTP is not much better. It also isn’t supported on all the versions of Windows we target, argh. It turns out that you can get libcurl [one of favorite libraries] to work on Windows within Visual Studio. Here is a quick overview how to make it happen with the 7.16.4 release.

  1. Download the source and load lib\curllib.vcproj in Visual Studio

  2. In curllib project properties->Configuration Properties->C/C++->Code Generation->Runtime Library change the value to Multi-Threaded /MT [assuming a release build] so it correctly builds as a static library

  3. Then in the project you intend to use libcurl – in the preprocessor section, define CURL_STATICLIB and add the curl include directories

  4. In the linker section add curllib.lib, ws2_32.lib, winmm.lib

  5. Prosper

For good measure, I’ve uploaded a release build of this lib that you can link to in your project [skip steps 1 and 2]

24 Responses to “libcurl on Windows with Visual Studio 2005”

  1. Henry Baxter Says:

    I spent FOREVER working on this. Thank you so much for helping me out by writing this blog post.

  2. Ron Says:

    Would you happen to know how to take this one step further and build with libssh2 for ssh support — for sftp?

  3. Jeff Says:

    Haven’t explored that. I might update this with instructions on how to build in SSL support though.

  4. Natko Says:

    Well, it’s easy to build the lib, but I still don’t see how to solve the linker issues in my project which uses the lib.

    unresolved externals:

    curl_easy_cleanup curl_easy_perform curl_easy_setopt curl_easy_init … …

  5. Jeff Says:

    @Natko – Make sure you link the library. Those externals are in curllib.lib

  6. Anton Says:

    Thanks a lot! Your post was a great help.

  7. dblog » Blog Archive » curl references Says:

    [...] magnetk.com writes about how to build a recent libcurl with visual studio 2005 [...]

  8. Exorsus Says:

    Hi there, great work you’ve done :-) ….. this was a real pain in the ass for me.

  9. Jani Says:

    Thanks a bunch! I had hard time with this, but your post helped a lot!

  10. Magnetk Blog » Blog Archive » High Leverage Development Says:

    [...] ugly and verbose. Another option, WinHTTP, didn’t work on Windows 2000 GM. We ended up using libCURL. It was a ridiculous and frustrating waste of [...]

  11. Starbuck Says:

    Just got cURL 7.18.1 source and cURL.NET binding source (last build 2005) and was going to try to rebuild the .NET binding project with VS2005, then VS2008/.NET3. I’m a C# guy, not qualified to work with C++ but I did update and publish another OSS project so I’m not totally clueless. Anyway, I packed it up pretty quickly: There are environment vars and tweaks to configs, libs to include and other packages to include and update (OpenSSL, zLib…). Stuff like zLib hasn’t been updated in a couple years and some help pages suggest linking in stuff I’ve never heard of. No, I’m afraid this isn’t work for the lightweight. I’m not looking for a fish but a fishing pole – can anyone suggest some reading that will lead me to being able to create updated DLL’s so that anyone can simply “reference n run” their cURL-powered apps using any .NET/CLR language? I’d be happy to maintain some of this stuff but I don’t have a clue how to do the initial bundle. TYVM

  12. Elise Says:

    Like everyone else, you just saved me a ton of time!!

  13. Colin Says:

    Thanks for the pointers — saved me lots of time. I also had to link in wldap32.lib to get libcurl 7.19.0 to build with VS2008.

  14. Oak Says:

    Just a big THANK YOU again!

  15. Me Says:

    I’m missing winldap.h in VS 2005. Where an I get it?

  16. helper of ME Says:

    Hi Me,

    You don’t need th winldap.h if you are trying to compile Curlib.lib. You will need winldap.lib which you may find in your visual studio directory.

    I just fixed the compilation error for this today.

    I am trying to add the LibSSh2.lib in Curlib.lib. I can’t generate the Libssh2.lib because of some linking error. Any one has libssh2.lib?

  17. Kunsheng Says:

    This is what I have been looking for two months. Even libcurl mailing list didn’t give concrete step there. Simple but very useful! Thanks!

  18. Eddy B Says:

    You just saved me a great deal of time and frustration.

    I had already blown a couple hours and was sinking into a morass of linking issues between libcurl and zlib versions. (“the ordinal xxx could not be located” in the zlib1.dll) This avoids the problem entirely.

    Thank you!

  19. sedwo Says:

    omg! That’s what I was missing. I wasn’t including the libcurl.lib file. You are awesome. Thank you! :)

  20. Gagan Says:

    Thanks a lot…..Its was a great help…..keep up the good work :)

  21. Sak Says:

    Thx a lot. Experienced similar problems with PCRE library. I really wonder why the library authors fail to provide this kind of help to Windows users. It’s not just chance that everybody had this problem…

  22. Christophe BIDAL Says:

    Thx a lot!

  23. John Says:

    Another option is to install CMake. Download the cURL source (e.g. ‘C:\src’). Open a console shell. Ensure your run your desired vcvars32.bat to setup your build environment. Then do something like the following:

    C:\src> mkdir build C:\src> cd build C:\build> cmake -DCURL_STATICLIB=1 -G “NMake Makefiles” .. C:\build> nmake

    That’s it. You should have a static libcurl library sitting in the same directory. That produces a debug build. If you want a release build add something like “-DCMAKE_BUILD_TYPE=MinSizeRel” to the cmake command above. Note that, depending on what vcvars32.bat you run, you can have either 32-bit or 64-bit builds of libcurl as needed.

    Hope this helps.

  24. shaimagz Says:

    Hello. I’m trying to use the curl lib with Visual Studio 2005, and its seems like impossible. After i followed each step above I’m getting this error:

    1>LINK : fatal error LNK1181: cannot open input file ‘curllib.lib’

    I did linked that and all, so I dono why i get this error.

    -I don’t know where is the location of the ‘curllib.lib’. how does VS2005 knows where to get that lib file from?

    -what should i do with lib\curllib.vcproj after i modified its settings?

    I’m so confused so I’am sorry if its not a proper question..

    Thanks, Shai.

Leave a Reply

Subscribe:

Add to Google
RSS
Try ExpanDrive

If you’ve heard of SSH then you need ExpanDrive.