C++ 你如何为 x64 编译 OpenSSL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/158232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:19:47  来源:igfitidea点击:

How do you compile OpenSSL for x64?

c++cwindows64-bitwin64

提问by kgriffs

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

按照 INSTALL.W64 中的说明操作后,我遇到了两个问题:

  • 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.
  • 代码仍写入“out32”文件夹。我需要能够在我的工作站上链接到 32 位和 64 位版本的库,所以我不希望 64 位版本破坏 32 位库。
  • 输出仍然是32位!这意味着我在尝试从 x64 应用程序链接到库时收到“未解析的外部符号”错误。

回答by kgriffs

To compile the static libraries (both release and debug), this is what you need to do:

要编译静态库(发布和调试),您需要执行以下操作:

  1. Install Perl - www.activestate.com
  2. Run the "Visual Studio 2008 x64 Cross Tools Command Prompt" (Note: The regular command prompt WILL NOT WORK.)
  3. Configure with perl Configure VC-WIN64A no-shared no-idea
  4. Run: ms\do_win64a
  5. EDIT ms\nt.mak and change "32" to "64" in the output dirs:
  1. 安装 Perl - www.activestate.com
  2. 运行“Visual Studio 2008 x64 交叉工具命令提示符”(注意:常规命令提示符将不起作用。)
  3. 用 perl 配置 VC-WIN64A no-shared no-idea
  4. 运行:ms\do_win64a
  5. 编辑 ms\nt.mak 并将输出目录中的“32”更改为“64”:
    # The output directory for everything intersting
    OUT_D=out64.dbg
    # The output directory for all the temporary muck
    TMP_D=tmp64.dbg
    # The output directory for the header files
    INC_D=inc64
    INCO_D=inc64\openssl
  1. EDIT ms\nt.mak and remove bufferoverflowu.lib from EX_LIBS if you get an error about it.
  2. Run: nmake -f ms\nt.mak
  3. EDIT the ms\do_win64a file and ADD "debug" to all lines, except the "ml64" and the last two lines
  4. Run: ms\do_win64a
  5. Repeat steps 4 and 5
  6. EDIT the ms\nt.mak file and ADD /Zi to the CFLAG list!
  7. Run: nmake -f ms\nt.mak
  1. 如果出现错误,请编辑 ms\nt.mak 并从 EX_LIBS 中删除 bufferoverflowu.lib。
  2. 运行:nmake -f ms\nt.mak
  3. 编辑 ms\do_win64a 文件并将“调试”添加到所有行,除了“ml64”和最后两行
  4. 运行:ms\do_win64a
  5. 重复步骤 4 和 5
  6. 编辑 ms\nt.mak 文件并将 /Zi 添加到 CFLAG 列表中!
  7. 运行:nmake -f ms\nt.mak

回答by Dan

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

我使用1.0.1c源以这种方式解决了这个问题:

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

将此块添加到util/pl/VC-32.pl,就在该$o='\\';行之前。

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

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

将此块添加到util/pl/VC-32.pl,就在该if ($debug)行之前。

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

回答by Alejandro PC

Use Conan. It is very simple to install and use.

使用柯南。安装和使用非常简单。

You can request the files ready for use. For example for Linux x64 or usage with Visual Studio 2012. Here a sample instruction:

您可以请求准备好使用的文件。例如对于 Linux x64 或使用 Visual Studio 2012。这里有一个示例指令:

conan install OpenSSL/1.0.2g@lasote/stable -s arch="x86_64" -s build_type="Debug" -s compiler="gcc" -s compiler.version="5.3" -s os="Linux" -o 386="False" -o no_asm="False" -o no_rsa="False" -o no_cast="False" -o no_hmac="False" -o no_sse2="False" -o no_zlib="False" ...

conan install OpenSSL/1.0.2g@lasote/stable -s arch="x86_64" -s build_type="Debug" -s compiler="gcc" -s compiler.version="5.3" -s os="Linux" -o 386="False" -o no_asm="False" -o no_rsa="False" -o no_cast="False" -o no_hmac="False" -o no_sse2="False" -o no_zlib="False" ...

回答by Akumaburn

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

“您可能会感到惊讶:64 位人工制品确实在 out32* 子目录中输出,并且名称以 *32.dll 结尾。事实是 64 位编译目标到目前为止是对传统 32 位 Windows 目标的增量更改。大量编译标志仍然标记为“32”,尽管它们确实适用于 32 位和 64 位目标。”

So the first answer is no longer necessary.

因此,不再需要第一个答案。

Instructions can be found here:

说明可以在这里找到:

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

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

回答by lrascao

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

如果您在 cygwin 中构建,则可以使用以下脚本,假设 MSDEVPATH 已设置为您的 Visual Studio 目录

 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}

回答by Ranke

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.

自最初提出此问题以来,构建说明已更改。可以在此处找到新说明。请注意,您需要安装 perl 和 NASM,并且需要使用开发人员命令提示符。

回答by J.Javan

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

在撰写本指南时,最新版本的 OpenSSL 是 1.1.1a。

Environment:

环境:

  • Windows 10
  • MS Visual Studio 2017
  • 视窗 10
  • 微软 Visual Studio 2017

Prerequisites:

先决条件:

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

确保 Perl 和 NASM 都在 PATH 环境变量中。

Compiling x64:

编译 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
  1. 打开 x64 本机工具命令提示符
  2. perl 配置 VC-WIN64A --prefix=e:\projects\bin\OpenSSL\vc-win64a --openssldir=e:\projects\bin\OpenSSL\SSL
  3. 制作
  4. 测试
  5. 安装

Step 4 is optional.

第 4 步是可选的。

Compiling x86:

编译 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
  1. 打开 x86 本机工具命令提示符
  2. perl 配置 VC-WIN32 --prefix=e:\projects\bin\OpenSSL\vc-win32 --openssldir=e:\projects\bin\OpenSSL\SSL
  3. 制作
  4. 测试
  5. 安装

Step 4 is optional.

第 4 步是可选的。

回答by rubenvb

You can also use MSYS+mingw-w64:

您还可以使用 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/

1) 下载并解压 msys 到 C:\msys
2) 下载并解压 mingw-w64 到 c:\mingw64
3) 运行 msys postinstall 脚本。当它要求您安装 mingw 时,将其指向 C:\mingw64\bin
4) 提取 openssl 每日快照(1.0.0 版本有一个错误)。在源目录中运行 configure mingw64
make
make check
make install
5)openssl 安装到 /local/