views:

4660

answers:

4

Hi,

I'm using libcurl in a Win32 C++ application.

I have the curllib.vcproj project added to my solution and set my other projects to depend on it.

How do I build it with SSL support enabled?

+11  A: 

Well, since this post failed badly, I had to dig into the matter myself.

So here goes:

Preprocessor

The following two symbols need to be fed to the preprocessor to enable SSL for libcurl:

USE_SSLEAY
USE_OPENSSL

(libcurl uses OpenSSL for SSL support)

Alternatively the symbols can be added directly to a file called setup.h in libcurl, but I'm not too happy about modifying code in 3rd party distributions unless I really have to.

Rebuilding the libcurl library, I now got some errors about OpenSSL include files not being found. Naturally, since I haven't set up the OpenSSL distribution properly yet.

Compiling OpenSSL binaries

I downloaded the OpenSSL 0.9.8 source distribution and unpacked it.

In the root of the source distribution there's a file called INSTALL.W32 which describes how to compile the OpenSSL binaries. The build chain requires perl, so I installed the latest version of ActivePerl.

I had some trouble with the build, which might not be applicable to all systems, but I'll go through it here in case somebody experiences the same.

According to INSTALL.W32:

Run the following commandline tasks with current directory set to the source distribution root:

1> perl Configure VC-WIN32 --prefix=c:/some/openssl/dir

(Where "c:/some/openssl/dir" should be replaced by the dir where OpenSSL should be installed. Don't use spaces in this path. The compilation further ahead will fail in that case)

2> ms\do_ms

(For me this step was unsuccessful at first, since I lacked the environment variables OSVERSION and TARGETCPU. I set these to 5.1.2600 and x86 respectively. You may get complaint about OSVERSION being "insane", but look closer, this error is for WinCE and doesn't affect the Win32 setup.)

3> nmake -f ms\nt.mak (for static library)

or

3> nmake -f ms\ntdll.mak (for DLL)

The source now compiles. Took approx 5 minutes on my laptop.

When compilation is completed, the libs or binaries have been placed in:

distroot/out32 - for static library build

or

distroot/out32dll - for DLL build

Building and linking

Now, back to visual studio and point out the libs and include path for headers. The include files are located in distroot/inc32/openssl.

Rebuild the libcurl project.

Error!

Well at least for me with this version of OpenSSL. it complained about a struct typedef in one of the OpenSSL headers. I couldn't find any info on this. After an hour of googling I broke my own principle and commented out the typedef from the OpenSSL header, and luckily libcurl wasn't using that symbol so it built fine.

Now, for confirming that SSL support is enabled for libcurl, run the following code:

curl_version_info_data * vinfo = curl_version_info( CURLVERSION_NOW );
if( vinfo->features & CURL_VERSION_SSL )
    // SSL support enabled
else
    // No SSL


Simple as that.

Regards.

/Robert

sharkin
Thanks helped alot!
Lodle
Thank you. Too bad the libcurl guys do not provide something ready to use in Windows.
Wartin
+1  A: 

i did "do_nt.bat" for windows 7 rc7100 don't forget "nmake -f ms\nt.mak install" to copy the headers correctly

thanks this did help a lot

+1  A: 

Couple of notes in response to and/or in addition to the above..

First, if you don't want to mess with ActivePerl, Strawberry Perl is terrific and worked perfectly for this.

Second, in lieu of using do_ms.bat, I would recommend preferring do_masm if possible since, according to INSTALL.W32,

This is worth doing because it will result in faster code: for example it will typically result in a 2 times speedup in the RSA routines.

Also, build 0.9.8l (L) of OpenSSL was a nightmare so I eventually gave up and reverted to 0.9.8k which built and linked (statically) with libcurl 1.9 without issue.

hemp
+2  A: 

When compiling OpenSSL 1.0.0 on Windows with Visual Studio 2010, it eventually threw a 0x2 error:

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0 \VC\BIN\cl.EXE"' : return code '0x2'

Stop.

It seems that this error will be thrown because of a flag in the perl Configure file, namely -WX. As the MSDN documentation states:

Treats all compiler warnings as errors. For a new project, it may be best to use /WX in all compilations; resolving all warnings will ensure the fewest possible hard-to-find code defects.

After removing the -WX occurrences in the Configure file and re-entering the commands stated here it built fine and passed all tests.

GaMer13
KTC