How to compile OpenSSL on Windows?

10,163

Solution 1

On the same my blog page which you refer I also describe 'no-asm' case - this case is simpler for compiling (it won't require nasm at all), but drawback is - some algorithms performance will be 2x-4x slower than assembler versions. If your case can accept this performance - try to compile 'no-asm' case.

perl Configure VC-WIN32 no-asm --prefix=C:\Build-OpenSSL-VC-32

Solution 2

I built the library from a regular command prompt on Windows 10 with VS 2015 with the following commands (debug build shown):

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
perl Configure debug-VC-WIN64A --prefix=C:\Path\to\target\folder
ms\do_win64a
nmake -f ms\ntdll.mak
cd out32dll.dbg
..\ms\test
cd ..
nmake -f ms\ntdll.mak install

Solution 3

I know this is an old post, but for others having the problem with NASM parsing errors, here's the solution:

Once you run either ms\do_ms.bat (to use masm) or ms\do_nasm.bat (to use nasm), you can't just switch to the other one without first clearing out the tmp32 directory, otherwise perl will never regenerate the .asm files correctly. The parser errors you're getting are from nasm trying to assemble a masm-formatted file.

The easiest way to clean out tmp32 is to run "nmake -f ms\nt.mak clean".

Solution 4

Answering to this very old question. There are a couple of problems associated with building it under x64 that way including hitting "assemblers not found", downloading NASM and adding to path etc. There is a very good and simple solution using MSYS2.

Install MSYS2. Ensure you get the toolchain needed (see the guide for pacman). Then follow below steps $Launch msys2_shell.cmd -mingw64

$wget -c ftp://ftp.pca.dfn.de/pub/tools/net/openssl/source/openssl-1.0.2o.tar.gz

$tar -xzvf openssl-1.0.2o.tar.gz openssl-1.0.2o/

$cd openssl-1.0.2o/

$./configure shared mingw64

$make

That's it. In apps directory you will get openssl executable along with the libraries.

-Sreejith. D. Menon

Share:
10,163
Alex
Author by

Alex

I lead a double life. On one hand, I am a graduate student, seeking my Masters' degree in Computer Science. My bachelors degree is a double major in Computer Science and Pure Mathematics. I enjoy all of the benefits of that, such as late-night coding sessions, regular exams, research papers, and all that fun stuff! On the other hand, I am employed full-time as a Software Developer, reaping all of the benefits of that as well. Which includes, but is not limited to, busy days filled with meetings, design methodologies, and more coding. All in all, I stay very busy with both of my lives, it is amazing that I even have time to visit this website.

Updated on June 17, 2022

Comments

  • Alex
    Alex almost 2 years

    I have been following the instructions in the OpenSSL User Guide, which links to a guide by 3noch for compiling OpenSSL. Here are the tools/versions I am using:

    • ActiveState Perl v5.20.2
    • Microsoft Visual Studio 2012
    • Netwide Assembler (NASM) v2.12.02
    • OpenSSL 1.0.2j (source tarball)

    Following the instructions, I am able to execute the following commands without issue:

    perl Configure VC-WIN32 --prefix=C:\Build-OpenSSL-VC-32
    ms\do_ms
    

    Then, when I go on to execute

    nmake -f ms\nt.mak
    

    I receive the following

     Assembling: tmp32\sha1-586.asm
    tmp32\sha1-586.asm(1432) : error A2070:invalid instruction operands
    tmp32\sha1-586.asm(1576) : error A2070:invalid instruction operands
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0
    \VC\BIN\ml.EXE"' : return code '0x1'
    Stop.
    

    After looking into that issue, I found a blog post by HostageBrain that mentions that exact error, stating to use nasm to perform the compiling. So, I switched to this command sequence:

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

    However, once switching to the NASM variation, I receive the following errors:

    tmp32\sha1-586.asm:1: error: parser: instruction expected
    tmp32\sha1-586.asm:2: error: parser: instruction expected
    tmp32\sha1-586.asm:3: error: parser: instruction expected
    tmp32\sha1-586.asm:4: warning: label alone on a line without a colon might be in error
    tmp32\sha1-586.asm:5: warning: label alone on a line without a colon might be in error
    tmp32\sha1-586.asm:6: warning: label alone on a line without a colon might be in error
    tmp32\sha1-586.asm:7: error: symbol `IF' redefined
    tmp32\sha1-586.asm:7: error: parser: instruction expected
    tmp32\sha1-586.asm:8: error: parser: instruction expected
    tmp32\sha1-586.asm:9: error: comma expected after operand 1
    

    What I am looking for is to be able to compile OpenSSL into .lib files that I can then link to from other C++ projects, such as when compiling FreeTDS.