pthreads and OpenSSL
Post date: Sep 15, 2012 10:20:29 PM
I'm following instructions from Fragrant Memories and gaia-gis.
Instead of tar, you can put 7zip in your path; for me it's "/c/Program Files/7-zip".
Pre-requisites
zlib installed to /usr/local/
pthreads-w32
Download the latest pthreads win32 release from sourceware.org: pthreads-w32-2-9-1-release.tar.gz.
Extract it in your home directory using 7zip:
cd
tar xvfz pthreads-w32-2-9-1-release.tar.gz
cd pthreads-w32-2-9-1-release/
The latest version of mingw-32 needed a 2-line fix:
vim semaphore.h
Search for "unsigned int mode_t"
Add these lines after:
#else
#include <sys/types.h>
The resulting code block should look like this:
#if !defined(HAVE_MODE_T)
typedef unsigned int mode_t;
#else
#include <sys/types.h>
#endif
Build the library (I was surprised by how quickly it built):
make clean GC-static CFLAGS=-DHAVE_STRUCT_TIMESPEC
Install the library files:
cp pthread.h sched.h semaphore.h /usr/local/include
cp libpthreadGC2.a /usr/local/lib/
cp libpthreadGC2.a /usr/local/lib/libpthread.a
Use this environment variable to use pthreads as a static library:
export CPPFLAGS="-DPTW32_STATIC_LIB"
OpenSSL
OpenSSL is a requirement for building many fundamental packages such as wget, ssh. It will use pthreads.
openssl-1.1.x series has trouble building in MinGW, so we use 1.0.x
Download the tarball (.tar.gz) of the latest 1.0.x version from https://www.openssl.org/source/ to your home directory.
Latest version as of December 8, 2016 is 1.0.2j:
cd
tar xvfz openssl-1.0.2j.tar.gz
Configure the makefile using specific options for MinGW:
cd openssl-1.0.2j
./Configure --prefix=/usr/local -I/usr/local/include -L/usr/local/lib -lpthreadGC2 -lws2_32 \
-DHAVE_STRUCT_TIMESPEC -DPTW32_STATIC_LIB threads shared zlib mingw
Without specifying --prefix option, OpenSSL libraries are installed to /usr/local/ssl. It is better to use /usr/local.
You can run ./Configure --help to see other options.
Start the build process:
make
If you have trouble building the tests, be sure to use "tar" and not an outside program like winzip. These steps can help:
cp test/dummytest.c test/md2test.c
cp test/dummytest.c test/rc5test.c
cp test/dummytest.c test/jpaketest.c
Install OpenSSL to MinGW. This takes several minutes:
make install
What next?
You can build programs that depend on OpenSSL, such as wget and curl. Build libssh2 first.
Use certificate bundle
OpenSSL based programs can check a certificate bundle file when making secure connections.
Download the file from the curl website using wget:
cd /usr/local/ssl/certs/
wget http://curl.haxx.se/ca/cacert.pem
If you don't have wget, you can copy cacert.pem from your browser: http://curl.haxx.se/ca/cacert.pem
Add this line to your .profile:
export SSL_CERT_FILE=/usr/local/ssl/certs/cacert.pem