How to compile OpenSSL on Windows?

给你一囗甜甜゛ 提交于 2021-02-18 11:37:05

问题


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.


回答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



回答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



回答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".




回答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



来源:https://stackoverflow.com/questions/40007633/how-to-compile-openssl-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!