Aerosol Posted March 22, 2015 Report Posted March 22, 2015 (edited) Configuring libcurl 7.41.0 with OpenSSL for Visual Studio 2013In this tutorial I will go over configuring Visual Studio for seamless usage with the libcurl 7.41.0 and OpenSSL libraries. I have included references to articles found related to the compilation and common issues.What is curl?curl is a command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMTP, SMTPS, Telnet and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling and more.Required tools & libraries1.] Visual Studio 2013 for Desktop (Ultimate, Team, etc)2.] ActivePerl 5.20.13.] 7-Zip 9.20 for Extracting tar.gz4.] OpenSSL 1.0.25.] curl 7.41.0Compiling OpenSSL static librariesOpenSSL has made it quite easy with integrating Perl and Visual Studio to compile right from the Visual Studio Command Prompt.1.] Verify ActivePerl 5.20.1 and Visual Studio 2013 are correctly installed.2.] Download and extract OpenSSL with 7-Zip, in this example we will use: C:\openssl3.] Open the Visual Studio Developer Command Prompt4.]Start -> All Programs -> Visual Studio 2013 -> Visual Studio Tools -> Developer Command Prompt for VS20135.] Make sure to run as administrator in case there any file permission errors while executing PerlNow, we are ready to configure OpenSSL, as said there is no major changes that need made to make this function without issue. We have a few options depending on the specifics of your target base, in this case, I am going to deploy 32 bit static libraries as they work fine on the x64 based processor line.1.] In the command prompt, change to the directory you extracted OpenSSL, I used c:\openssl.2.]cd c:\opensslType the build that best suits your needs, you can just copy the following and it should execute without problem.Building the 32-bit static librariesperl Configure VC-WIN32 --prefix=C:\Build-OpenSSL-VC-32ms\do_msnmake -f ms\nt.mak nmake -f ms\nt.mak installBuilding the 32-bit static libraries with debug symbolsperl Configure debug-VC-WIN32 --prefix=C:\Build-OpenSSL-VC-32-dbgms\do_msnmake -f ms\nt.maknmake -f ms\nt.mak installBuilding the 64-bit static librariesperl Configure VC-WIN64A --prefix=C:\Build-OpenSSL-VC-64ms\do_win64anmake -f ms\nt.maknmake -f ms\nt.mak installBuilding the 64-bit static libraries with debug symbolsperl Configure debug-VC-WIN64A --prefix=C:\Build-OpenSSL-VC-64-dbgms\do_win64anmake -f ms\nt.maknmake -f ms\nt.mak installAfter executing it may take a minute, but will output your includes and static libraries afterwords. perl util/copy.pl "out32\openssl.exe C:\Build-OpenSSL-VC-32\bin"Copying: out32/openssl.exe to C:/Build-OpenSSL-VC-32/bin/openssl.exe perl util/mkdir-p.pl "C:\Build-OpenSSL-VC-32\ssl"created directory `C:/Build-OpenSSL-VC-32/ssl' perl util/copy.pl apps\openssl.cnf "C:\Build-OpenSSL-VC-32\ssl"Copying: apps/openssl.cnf to C:/Build-OpenSSL-VC-32/ssl/openssl.cnf perl util/copy.pl "out32\ssleay32.lib" "C:\Build-OpenSSL-VC-32\lib"Copying: out32/ssleay32.lib to C:/Build-OpenSSL-VC-32/lib/ssleay32.lib perl util/copy.pl "out32\libeay32.lib" "C:\Build-OpenSSL-VC-32\lib"Copying: out32/libeay32.lib to C:/Build-OpenSSL-VC-32/lib/libeay32.libNote: * If you are trying to link your libraries and receive an error relating to ml64, then your Visual Studio isn't configured as x64, you will need to go in the OpenSSL folder and delete the tmp32 folder and recompile as a 32 bit library, if this folder is not deleted you will continue to receive errors.1.] After it's compiled, go to the output directory, example, C:\Build-OpenSSL-VC-32.2.] Open your Visual Studio C directory, example, C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC.3.] Copy and merge the 'lib' and 'include' directory from the OpenSSL output directory into the 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC' directory.You are done with the OpenSSL portion.Compiling libcurl static librariesNow, that you have that done. We will need to configure libcurl. It has been made quite simple if you download the latest build, it comes with Visual Studio 2013 projects included.1.] Extract libcurl2.] Open libcurl folder, then go to:projects -> Windows -> VC123.] Open 'curl-all.sln'4.] Go to Build -> Uncheck 'curlsrc' as we don't need this.5.] Under 'libcurl', Choose LIB Release - LIB OpenSSL, as it will bind a static library that does not require exported DLLs.After it's done compiling, go to the 'curl-7.41.0' directory. Copy and merge the 'include' folder from there with 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC' as we did in the previous steps while setting up OpenSSL. There will also be a 'build' folder in the root of the 'curl-7.41.0' directory. build -> Win32 -> VC12 -> LIB Release - LIB OpenSSLCopy the file 'libcurl.lib' into the 'lib' folder located at 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC'.Since these are static libraries, not all functions from Windows have been previously exported. You will still need to link against 'Ws2_32.lib' and 'Wldap32.lib' for specific functions of 'libcurl' in Visual Studio, however you will not need any external DLL files.Make sure to define 'CURL_STATICLIB' in your Preprocessor Definitions.If you are having linker errors, try going to your Project Properties -> Linker -> Additional Dependencies in your Visual Studio project.Add the following:libcurl.liblibeay32.libssleay32.libws2_32.libwldap32.libYou should be good to go after this.Example source for Visual Studio 2013..#include "stdafx.h"#include <windows.h>#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://example.com"); /* example.com is redirected, so we tell libcurl to follow redirection */ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check for errors */ if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); } return 0;} References: http://developer.covenanteyes.com/building-openssl-for-visual-studio/Source: sludg3 @ TF Edited March 22, 2015 by Aerosol Quote