libcurl on Windows with Visual Studio 2005
July 27th, 2007Developing 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.
Download the source and load lib\curllib.vcproj in Visual Studio
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
Then in the project you intend to use libcurl – in the preprocessor section, define CURL_STATICLIB and add the curl include directories
In the linker section add curllib.lib, ws2_32.lib, winmm.lib
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]



August 8th, 2007 at 10:00 pm
I spent FOREVER working on this. Thank you so much for helping me out by writing this blog post.
August 29th, 2007 at 4:16 pm
Would you happen to know how to take this one step further and build with libssh2 for ssh support — for sftp?
August 29th, 2007 at 4:23 pm
Haven’t explored that. I might update this with instructions on how to build in SSL support though.
September 17th, 2007 at 2:47 am
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 … …
September 17th, 2007 at 2:12 pm
@Natko – Make sure you link the library. Those externals are in curllib.lib
September 22nd, 2007 at 1:48 pm
Thanks a lot! Your post was a great help.
October 28th, 2007 at 6:08 pm
[...] magnetk.com writes about how to build a recent libcurl with visual studio 2005 [...]
November 28th, 2007 at 10:24 am
Hi there, great work you’ve done :-) ….. this was a real pain in the ass for me.
January 9th, 2008 at 7:02 am
Thanks a bunch! I had hard time with this, but your post helped a lot!
March 26th, 2008 at 11:19 am
[...] 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 [...]
May 6th, 2008 at 2:42 am
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
October 15th, 2008 at 9:10 am
Like everyone else, you just saved me a ton of time!!
October 20th, 2008 at 5:14 pm
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.
April 9th, 2009 at 10:24 pm
Just a big THANK YOU again!
May 6th, 2009 at 10:08 pm
I’m missing winldap.h in VS 2005. Where an I get it?
May 7th, 2009 at 6:45 pm
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?
June 16th, 2009 at 9:03 pm
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!
July 2nd, 2009 at 6:22 pm
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!
July 31st, 2009 at 11:23 pm
omg! That’s what I was missing. I wasn’t including the libcurl.lib file. You are awesome. Thank you! :)
August 13th, 2009 at 5:06 am
Thanks a lot…..Its was a great help…..keep up the good work :)
November 19th, 2009 at 2:05 pm
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…
December 21st, 2009 at 6:31 am
Thx a lot!
February 5th, 2010 at 12:59 pm
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.
February 25th, 2010 at 6:02 pm
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.