How do you compile OpenSSL for x64?

2019-01-11 03:56发布

After following the instructions in INSTALL.W64 I have two problems:

  • The code is still written to the "out32" folder. I need to be able to link to both 32-bit and 64-bit versions of the library on my workstation, so I don't want the 64-bit versions to clobber the 32-bit libs.
  • The output is still 32-bit! This means that I get "unresolved external symbol" errors when trying to link to the libraries from an x64 app.

8条回答
爷的心禁止访问
2楼-- · 2019-01-11 04:30

According to the official documentation:

"You may be surprised: the 64bit artefacts are indeed output in the out32* sub-directories and bear names ending *32.dll. Fact is the 64 bit compile target is so far an incremental change over the legacy 32bit windows target. Numerous compile flags are still labelled "32" although those do apply to both 32 and 64bit targets."

So the first answer is no longer necessary.

Instructions can be found here:

https://wiki.openssl.org/index.php/Compilation_and_Installation#W64

查看更多
家丑人穷心不美
3楼-- · 2019-01-11 04:38

At the time of writing this how-to the most recent version of OpenSSL is 1.1.1a.

Environment:

  • Windows 10
  • MS Visual Studio 2017

Prerequisites:

Make sure both Perl and NASM are in PATH environment variable.

Compiling x64:

  1. Open x64 Native Tools Command Prompt
  2. perl Configure VC-WIN64A --prefix=e:\projects\bin\OpenSSL\vc-win64a --openssldir=e:\projects\bin\OpenSSL\SSL
  3. nmake
  4. nmake test
  5. nmake install

Step 4 is optional.

Compiling x86:

  1. Open x86 Native Tools Command Prompt
  2. perl Configure VC-WIN32 --prefix=e:\projects\bin\OpenSSL\vc-win32 --openssldir=e:\projects\bin\OpenSSL\SSL
  3. nmake
  4. nmake test
  5. nmake install

Step 4 is optional.

查看更多
聊天终结者
4楼-- · 2019-01-11 04:39

If you're building in cygwin, you can use the following script, assume MSDEVPATH has already been set to your Visual Studio dir

 echo "Building x64 OpenSSL"
 # save the path of the x86 msdev
 MSDEVPATH_x86=$MSDEVPATH
 # and set a new var with x64 one
 MSDEVPATH_x64=`cygpath -u $MSDEVPATH/bin/x86_amd64`

 # now set vars with the several lib path for x64 in windows mode
 LIBPATH_AMD64=`cygpath -w $MSDEVPATH_x86/lib/amd64`
 LIBPATH_PLATFORM_x64=`cygpath -w $MSDEVPATH_x86/PlatformSDK/lib/x64`
 # and set the LIB env var that link looks at
 export LIB="$LIBPATH_AMD64;$LIBPATH_PLATFORM_x64"

 # the new path for nmake to look for cl, x64 at the start to override any other msdev that was set previously
 export PATH=$MSDEVPATH_x64:$PATH

 ./Configure VC-WIN64A zlib-dynamic --prefix=$OUT --with-zlib-include=zlib-$ZLIB_VERSION/include --with-zlib-lib=zlib-$ZLIB_VERSION/x64_lib

 # do the deed
 ms/do_win64a.bat
 $MSDEVPATH_x86/bin/nmake -f ms/ntdll.mak  ${1:-install}
查看更多
趁早两清
5楼-- · 2019-01-11 04:41

You can also use MSYS+mingw-w64:

1) download and extract msys to C:\msys
2) download and extract mingw-w64 to c:\mingw64
3) run msys postinstall script. When it asks for your mingw installation, point it to C:\mingw64\bin
4) Extract an openssl daily snapshot (1.0.0 release has a bug). In the source dir run configure mingw64
make
make check
make install
5) openssl is installed to /local/

查看更多
你好瞎i
6楼-- · 2019-01-11 04:48

I solved the problem this way, using the 1.0.1c source:

Add this block to util/pl/VC-32.pl, just before the $o='\\'; line.

if ($debug)
    {
    $ssl .= 'd';
    $crypto .= 'd';
    }

Add this block to util/pl/VC-32.pl, just before the if ($debug) line.

if ($FLAVOR =~ /WIN64/)
    {
    $out_def =~ s/32/64/;
    $tmp_def =~ s/32/64/;
    $inc_def =~ s/32/64/;
    }

Then build all varieties:

setenv /x86 /release
perl Configure VC-WIN32  --prefix=build -DUNICODE -D_UNICODE
ms\do_ms
nmake -f ms\ntdll.mak

setenv /x64 /release
perl Configure VC-WIN64A --prefix=build
ms\do_win64a.bat
nmake -f ms\ntdll.mak

setenv /x86 /debug
perl Configure debug-VC-WIN32  --prefix=build -DUNICODE -D_UNICODE
ms\do_ms
move /y ms\libeay32.def ms\libeay32d.def
move /y ms\ssleay32.def ms\ssleay32d.def
nmake -f ms\ntdll.mak

setenv /x64 /debug
perl Configure debug-VC-WIN64A --prefix=build
ms\do_win64a.bat
move /y ms\libeay32.def ms\libeay32d.def
move /y ms\ssleay32.def ms\ssleay32d.def
nmake -f ms\ntdll.mak
查看更多
疯言疯语
7楼-- · 2019-01-11 04:50

The build instructions have changed since this question was originally asked. The new instructions can be found here. Note that you will need to have perl and NASM installed, and you will need to use the developer command prompt.

查看更多
登录 后发表回答