Jump to content
Aerosol

Configuring libcurl 7.41.0 with OpenSSL for Visual Studio 2013

Recommended Posts

Configuring libcurl 7.41.0 with OpenSSL for Visual Studio 2013

In 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 & libraries

1.] Visual Studio 2013 for Desktop (Ultimate, Team, etc)

2.] ActivePerl 5.20.1

3.] 7-Zip 9.20 for Extracting tar.gz

4.] OpenSSL 1.0.2

5.] curl 7.41.0

Compiling OpenSSL static libraries

OpenSSL 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:\openssl

3.] Open the Visual Studio Developer Command Prompt

4.]

Start -> All Programs -> Visual Studio 2013 -> Visual Studio Tools -> Developer Command Prompt for VS2013

5.] Make sure to run as administrator in case there any file permission errors while executing Perl

Now, 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:\openssl

Type the build that best suits your needs, you can just copy the following and it should execute without problem.

Building the 32-bit static libraries

perl Configure VC-WIN32 --prefix=C:\Build-OpenSSL-VC-32
ms\do_ms
nmake -f ms\nt.mak
nmake -f ms\nt.mak install

Building the 32-bit static libraries with debug symbols

perl Configure debug-VC-WIN32 --prefix=C:\Build-OpenSSL-VC-32-dbg
ms\do_ms
nmake -f ms\nt.mak
nmake -f ms\nt.mak install

Building the 64-bit static libraries

perl Configure VC-WIN64A --prefix=C:\Build-OpenSSL-VC-64
ms\do_win64a
nmake -f ms\nt.mak
nmake -f ms\nt.mak install

Building the 64-bit static libraries with debug symbols

perl Configure debug-VC-WIN64A --prefix=C:\Build-OpenSSL-VC-64-dbg
ms\do_win64a
nmake -f ms\nt.mak
nmake -f ms\nt.mak install

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

Note: * 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 libraries

Now, 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 libcurl

2.] Open libcurl folder, then go to:

projects -> Windows -> VC12

3.] 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 OpenSSL

Copy 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.lib
libeay32.lib
ssleay32.lib
ws2_32.lib
wldap32.lib

You 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 by Aerosol
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...