Thursday, October 8, 2009

compile openssl for mingw

I was googling a correct step to build openssl with mingw. I followed different posts from different people, none of them give me anything good. After a whole afternoon of trying and failing, eventually, I got it right with following steps:
1. install cygwin on my PC. To avoid too much trying and failing, I have installed the full cygwin. Storage space is cheap but time is very expensive.
2. install mingw
3. download openssl from openssl.org. I used 0.9.8k
4. untar/unzip 0.9.8k package to cygwin how directory
5. start Cygwin xterm (ya, Cygwin not msys)
6. in the xterm, go to openssl-0.9.8k directory that you just unpacked
7. ./Configure mingw
8. make

The steps above create static library that can be used with mingw. To create the dll, you need to do:
$ echo EXPORTS > libcrypto.def
$ nm libcrypto.a | grep ' T _' | sed 's,^.* T _,,' >> libcrypto.def
$ dllwrap -o libcrypto.dll --def libcrypto.def libcrypto.a -lws2_32 -lgdi32
$ echo EXPORTS > libssl.def
$ nm libssl.a | grep 'T _' | sed 's,^.* T _,,' >> libssl.def
$ dllwrap -o libssl.dll --def libssl.def libssl.a libcrypto.dll
After this, you can copy the *.a to /mingw/lib and *.dll to /ming/bin

1 comment:

  1. This process didn't seem to work for me. Cygwin does manage to build everything successfully, but taking the resultant .a files it produces and attempting to compile them into QT in mingw produces a lot of errors like:
    undefined reference _imp____ctype_ptr__

    These errors don't come out when I use the precompiled openssl distributed by slproweb.

    ReplyDelete