Pages

Friday, May 26, 2017

Add CURL in Visual Studio (C++) easy, not bullshit, works

Looking for something that fixes your day because you are having a nightmare with CURL or libcurl? Tired of finding just stupid tutorials in the internet that never work or are crazy complex? Lets cut the bullshit.

I'm not telling you what CURL is now, but I'll tell you this shit is tricky to implement. I'll try to show you from the very beginning. In my case I used Visual Studio 2012, C++ and CURL 7.54.0.

To start, I'll tell you, you can't download from the official website (nor from fucking anywhere, as it seems) what really needs to implement CURL. What you get are the files for building the other files that are the good stuff. I had to build mine ones so I'll give you a link to download them, though I don't really know if these work for everyone (I presume they do). Anyway, I'll show you how to build your own ones, so jump to the implementation part if you use my stuff.


Building

This is to build the files you need to import to your project.
First, download the zip from the CURL site, get the file from the section "Source Archives".

https://curl.haxx.se/download.html

1. Extract them somewhere and go to the folder "winbuild". Copy the path to that folder.
2. Go to your programs and find "VS2012 x86 Native Tools Command Prompt" or you equivalent.
3. Run it and cd to the path to the point 1. For that, write: cd pasteHereThePath and press enter.
4. Now write the following: nmake /f Makefile.vc mode=static VC=12
5. Change the number 12 for the number of your Visual Studio version. E.g. VS 2015 then VC=15. Press enter

Now it should start the building. Wait.

In the folder where you extracted the zip file, a new folder called "builds" must have been created. Follow this paths to find the results of the build:
builds/libcurl-vc12-x86-release-static-ipv6-sspi-winssl/include here is the "curl" folder
builds/libcurl-vc12-x86-release-static-ipv6-sspi-winssl/lib here is the .lib file

6. Get the "curl" folder and the .lib file called "libcurl_a.lib". Forget every other file.

Implementing

Now that you have the folder and the .lib (I recommend moving the file into the folder), put then somewhere reasonable for your project (I assume you already created a VS project), for example in the project root folder.

To get VS to work with the new files, we must tune some options:

1. In the "Solution Explorer", right click in your project and click "Properties".
2. Go to "Configuration Properties" -> "VC++ Directories". In the fields "Include Directories" and "Library Directories" add the path to the curl folder and to the .lib respectively. If you followed my advise, the folder must be the same for both. It's also a good idea to use relative paths or macros, but now it's not time to go into details.
3. Go to  "Configuration Properties" -> "Linker" -> "Input". In the field "Additional Dependencies" add the name of the .lib file: "libcurl_a.lib"
4. Go to  "Configuration Properties" -> "C/C++" -> "Code Generation". In the field "Runtime Library"select "Multi-threaded DLL (/MD)".
5. Click OK and move on.

There you have it, after all this, you must be able to create a .cpp file and include "curl.h" without trouble. Here are examples of code, by the way: https://curl.haxx.se/libcurl/c/example.html

Tell me in the comments if this was of any help to you.

No comments:

Post a Comment