How to build OpenSSL in VS2015: x86cpuid.asm is an empty file
Building OpenSSL 1.0.2d as a static library on Windows
Note: Following text is extracted from my building instructions for SoftHSM2.
Required software
- Visual Studio (2015 Community)
- GNU Privacy Guard for Windows (2.2.5)
- 7-zip (9.20)
- Strawberry Perl (5.22.0.1)
- The Netwide Assembler (2.11.08)
Preparations
Create working directories:
mkdir C:\build\bin\
mkdir C:\build\src\
Download OpenSSL 1.0.2d with its signature into C:\build\src\
directory and verify signature of the downloaded archive:
cd C:\build\src\
gpg --keyserver pgp.mit.edu --recv-keys 0E604491
gpg --verify openssl-1.0.2d.tar.gz.asc openssl-1.0.2d.tar.gz
Building 32-bit version
Extract archive openssl-1.0.2d.tar.gz
into C:\build\src\openssl-1.0.2d-x86
directory:
cd C:\build\src\
"C:\Program Files\7-Zip\7z" x openssl-1.0.2d.tar.gz
"C:\Program Files\7-Zip\7z" x openssl-1.0.2d.tar
rename openssl-1.0.2d openssl-1.0.2d-x86
del openssl-1.0.2d.tar
In a new command line window build OpenSSL and install it into C:\build\bin\openssl-1.0.2d-x86
directory:
cd C:\build\src\openssl-1.0.2d-x86
set PATH=%PATH%;C:\nasm
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
perl Configure VC-WIN32 --prefix=C:\build\bin\openssl-1.0.2d-x86 enable-static-engine
ms\do_nasm
nmake /f ms\nt.mak
nmake /f ms\nt.mak test
nmake /f ms\nt.mak install
Resulting build is located in C:\build\bin\openssl-1.0.2d-x86
directory.
Building 64-bit version
Extract archive openssl-1.0.2d.tar.gz
into C:\build\src\openssl-1.0.2d-x64
directory:
cd C:\build\src\
"C:\Program Files\7-Zip\7z" x openssl-1.0.2d.tar.gz
"C:\Program Files\7-Zip\7z" x openssl-1.0.2d.tar
rename openssl-1.0.2d openssl-1.0.2d-x64
del openssl-1.0.2d.tar
In a new command line window build OpenSSL and install it into C:\build\bin\openssl-1.0.2d-x64
directory:
cd C:\build\src\openssl-1.0.2d-x64
set PATH=%PATH%;C:\nasm
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
perl Configure VC-WIN64A --prefix=C:\build\bin\openssl-1.0.2d-x64 enable-static-engine
ms\do_win64a
nmake /f ms\nt.mak
nmake /f ms\nt.mak test
nmake /f ms\nt.mak install
Resulting build is located in C:\build\bin\openssl-1.0.2d-x64
directory.
JDługosz
Updated on June 13, 2022Comments
-
JDługosz almost 2 years
I need to build OpenSSL for a project that's using VS2015, 32-bit.
The instructions I found are http://developer.covenanteyes.com/building-openssl-for-visual-studio/ and an updated/edited version reportedly using VS2015 at http://blog.box.kr/?p=953 .
In the directory where I unpacked the distribution, I first did
cl
to verify that I had a MS Compiler build prompt (as set up by their batch file), andperl -v
to make sure I had Perl. Then,perl Configure VC-WIN32 no-idea no-mdc2 no-rc5 --prefix=e:\some\path ms\do_ms nmake -f ms\nt.mak
and at this last step I get:
Building OpenSSL perl .\util\copy-if-different.pl ".\crypto\buildinf.h" "tmp32\buildinf.h" Copying: ./crypto/buildinf.h to tmp32/buildinf.h perl .\util\copy-if-different.pl ".\crypto\opensslconf.h" "inc32\openssl\opensslconf.h" Copying: ./crypto/opensslconf.h to inc32/openssl/opensslconf.h ml /nologo /Cp /coff /c /Cx /Zi /Fotmp32\x86cpuid.obj tmp32\x86cpuid.asm Assembling: tmp32\x86cpuid.asm tmp32\x86cpuid.asm(1) : error A2088:END directive required at end of file NMAKE : fatal error U1077: '"D:\@Prog-Charon\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\ml.EXE"' : return code '0x1' Stop.
I find that
E:\C++Libs\openssl-1.0.2e\tmp32\x86cpuid.asm
is a zero-length file.What I really want is to have (build or find ready-made) a static library for a project that will use the dynamic run-time library.
Update: if I run the step manually,
perl crypto\x86cpuid.pl win32 > tmp32\x86cpuid.asm
then when the makefile gets to that file it gives me
ml /nologo /Cp /coff /c /Cx /Zi /Fotmp32\x86cpuid.obj tmp32\x86cpuid.asm Assembling: tmp32\x86cpuid.asm tmp32\x86cpuid.asm(35) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(59) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(64) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(70) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(75) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(90) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(98) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(105) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(165) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(182) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(186) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(322) : error A2085:instruction or register not accepted in current CPU mode tmp32\x86cpuid.asm(335) : error A2085:instruction or register not accepted in current CPU mode NMAKE : fatal error U1077: '"D:\@Prog-Charon\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\ml.EXE"' : return code '0x1'
Now it happens that line 35 etc. is
cpuid
, which is the whole point of having this file! -
JDługosz over 8 yearsThe difference between your post and what I cited (and reported) is "do_nasm" which I suppose means it uses nasm instead of masm. That's interesting since asm files are where I'm having problems, but directly contradict other guides which say "it's a mistake to use nasm...visual studio handles it directly" and likewise that Strawberry Perl is known to be problematic and that ActiveState should be used. Also you used an older version. And, you were helpful enough to give the exact versions of the various tools you were using, which earns my upvote even though I have not retried it yet.
-
jariq over 8 years@JDługosz I was trying to build it without nasm at first but the build was failing hard so after a bit of searching I found information from Andy Polyakov (member of OpenSSL core dev team) that nasm is preferred option. Strawberry Perl was used because ActiveState is making it harder and harder every year to download free version from their website. So I have migrated to Strawberry Perl and I really like it so far.
-
JDługosz over 8 yearsThat's good to know re nasm. Other people post things and presumably it worked for them... maybe the exact version of VS/masm or of OpenSSL changes this.
-
Kuba hasn't forgotten Monica about 8 yearsI confirm that this works with VS2015, nasm and ActiveState perl.
-
MatrixManAtYrService almost 8 yearsIn my experience (while following the 32 bit instructions) calling vcvarsall.bat lead to this error:
module machine type 'X86' conflicts with target machine type 'x64'
Fixed it by callingC:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat
instead. -
karliwson almost 7 yearsPerfect. I used the same instructions with VS2017. Everything ok!