OpenSSL 1.1.1 Windows 编译说明

使用翻译器,不保证准确性。

Requirement details
-------------------

In addition to the requirements and instructions listed in INSTALL, these are required as well:

- Perl.
  We recommend ActiveState Perl, available from https://www.activestate.com/ActivePerl.
  Another viable alternative appears to be Strawberry Perl, http://strawberryperl.com.
  You also need the perl module Text::Template, available on CPAN.
  Please read NOTES.PERL for more information.

- Microsoft Visual C compiler.
  Since we can't test them all, there is unavoidable uncertainty about which versions are supported.
  Latest version along with couple of previous are certainly supported.
  On the other hand oldest one is known not to work.
  Everything between falls into best-effort category.

- Netwide Assembler, a.k.a. NASM, available from https://www.nasm.us, is required.
  Note that NASM is the only supported assembler.
  Even though Microsoft provided assembler is NOT supported, contemporary 64-bit version is exercised through continuous integration of VC-WIN64A-masm target.


Installation directories
------------------------

The default installation directories are derived from environment variables.

For VC-WIN32, the following defaults are use:

    PREFIX:      %ProgramFiles(86)%\OpenSSL
    OPENSSLDIR:  %CommonProgramFiles(86)%\SSL

For VC-WIN64, the following defaults are use:

    PREFIX:      %ProgramW6432%\OpenSSL
    OPENSSLDIR:  %CommonProgramW6432%\SSL

Should those environment variables not exist (on a pure Win32 installation for examples), these fallbacks are used:

    PREFIX:      %ProgramFiles%\OpenSSL
    OPENSSLDIR:  %CommonProgramFiles%\SSL

ALSO NOTE that those directories are usually write protected, even if your account is in the Administrators group.
To work around that, start the command prompt by right-clicking on it and choosing "Run as Administrator" before running 'nmake install'.
The other solution is, of course, to choose a different set of directories by using --prefix and --openssldir when configuring.

mingw and mingw64
=================

* MSYS2 shell and development environment installation:

  Download MSYS2 from https://msys2.github.io/ and follow installation instructions.
  Once up and running install even make, perl, (git if needed,) mingw-w64-i686-gcc and/or mingw-w64-x86_64-gcc.
  You should have corresponding MinGW items on your start menu, use *them*, not generic MSYS2.
  As implied in opening note, difference between them is which compiler is found 1st on $PATH.
  At this point ./config should recognize correct target, roll as if it was Unix...

* It is also possible to build mingw[64] on Linux or Cygwin by configuring with corresponding --cross-compile-prefix= option.
  For example

    ./Configure mingw --cross-compile-prefix=i686-w64-mingw32- ...

  or

    ./Configure mingw64 --cross-compile-prefix=x86_64-w64-mingw32- ...

  This naturally implies that you've installed corresponding add-on packages.

Independently of the method chosen to build for mingw, the installation paths are similar to those used when building with VC-* targets, except that in case the fallbacks mentioned there aren't possible (typically when cross compiling on Linux), the paths will be the following:

For mingw:

    PREFIX:      C:/Program Files (x86)/OpenSSL
    OPENSSLDIR   C:/Program Files (x86)/Common Files/SSL

For mingw64:

    PREFIX:      C:/Program Files/OpenSSL
    OPENSSLDIR   C:/Program Files/Common Files/SSL

Linking your application
========================

This section applies to all "native" builds.

If you link with static OpenSSL libraries then you're expected to additionally link your application with WS2_32.LIB, GDI32.LIB, ADVAPI32.LIB, CRYPT32.LIB and USER32.LIB.
Those developing non-interactive service applications might feel concerned about linking with GDI32.LIB and USER32.LIB, as they are justly associated with interactive desktop, which is not available to service processes.
The toolkit is designed to detect in which context it's currently executed, GUI, console app or service, and act accordingly, namely whether or not to actually make GUI calls.
Additionally those who wish to /DELAYLOAD:GDI32.DLL and /DELAYLOAD:USER32.DLL and actually keep them off service process should consider implementing and exporting from .exe image in question own _OPENSSL_isservice not relying on USER32.DLL.
E.g., on Windows Vista and later you could:

    __declspec(dllexport) __cdecl BOOL _OPENSSL_isservice(void)
    {   DWORD sess;
        if (ProcessIdToSessionId(GetCurrentProcessId(),&sess))
            return sess==0;
        return FALSE;
    }

If you link with OpenSSL .DLLs, then you're expected to include into your application code small "shim" snippet, which provides glue between OpenSSL BIO layer and your compiler run-time.
See the OPENSSL_Applink manual page for further details.

Cygwin, "hosted" environment
============================

Cygwin implements a Posix/Unix runtime system (cygwin1.dll) on top of the Windows subsystem and provides a bash shell and GNU tools environment.
Consequently, a make of OpenSSL with Cygwin is virtually identical to the Unix procedure.

To build OpenSSL using Cygwin, you need to:

* Install Cygwin (see https://cygwin.com/)

* Install Cygwin Perl and ensure it is in the path. Recall that as least 5.10.0 is required.

* Run the Cygwin bash shell

Apart from that, follow the Unix instructions in INSTALL.

NOTE: "make test" and normal file operations may fail in directories mounted as text (i.e. mount -t c:\somewhere /home) due to Cygwin stripping of carriage returns.
To avoid this ensure that a binary mount is used, e.g. mount -b c:\somewhere /home.

需求详情
-------

除了install中列出的要求和说明外,还需要这些。

- Perl。
  我们推荐使用 ActiveState Perl,可以从 https://www.activestate.com/ActivePerl 了解。
  另一个可行的选择似乎是 Strawberry Perl,http://strawberryperl.com。
  你还需要 perl 模块 Text:::Template,可以在 CPAN 上找到。
  请阅读 NOTES.PERL 了解更多信息。

- Microsoft Visual C 编译器。
  由于我们无法对所有的编译器进行测试,所以难免会有不确定性,不知道支持哪些版本。
  最新的版本和之前的几个版本肯定是支持的。另一方面,最老版本的版本也不支持。
  这两者之间的一切都属于最佳努力的范畴。

- 需要使用 Netwide Assembler,又名 NASM,可从 https://www.nasm.us 了解。
  注意,NASM 是唯一支持的汇编器。
  尽管不支持微软提供的汇编器,但通过VC-WIN64A-asm目标的持续集成,可以使用当代的64位版本。


安装目录
-------

默认的安装目录来自环境变量。

对于 VC-WIN32,使用以下默认值:

    PREFIX:      %ProgramFiles(86)%\OpenSSL
    OPENSSLDIR:  %CommonProgramFiles(86)%\SSL

对于 VC-WIN64,使用以下默认值:

    PREFIX:      %ProgramW6432%\OpenSSL
    OPENSSLDIR:  %CommonProgramW6432%\SSL

如果这些环境变量不存在(以纯 Win32 安装为例),则使用这些备用:

    PREFIX:      %ProgramFiles%\OpenSSL
    OPENSSLDIR:  %CommonProgramFiles%\SSL

另外请注意,这些目录通常是受写保护的,即使你的账户在 Administrators 组中。
要解决这个问题,可以在命令提示符上点击右键,选择 "以管理员身份运行",然后运行 "nmake install"。
当然,另一种方法是在配置时使用 --prefix和--openssldir 选择不同的目录。

mingw 和 mingw64
================

* MSYS2 shell 和 开发环境 安装。

  从 https://msys2.github.io/ 下载 MSYS2 并按照安装说明进行安装。
  一旦启动并运行后,甚至安装 make、perl、(如果需要的话,安装 git) mingw-w64-i686-gcc 和/或 mingw-w64-x86_64-gcc。
  你的开始菜单上应该有相应的 MinGW 项目,使用 "它们",而不是通用的 MSYS2。
  正如开篇注释所暗示的,它们之间的区别在于在 $PATH 上找到的是哪个编译器。
  在这一点上,./config 应该可以识别出正确的目标,就像 Unix 一样滚动。

* 也可以通过配置相应的 --cross-compile-prefix= 选项来在 Linux 或 Cygwin 上构建 mingw[64]。
  举例来说

    ./Configure mingw --cross-compile-prefix=i686-w64-mingw32- ...

  或

    ./Configure mingw64 --cross-compile-prefix=x86_64-w64-mingw32- ...

  这自然意味着你已经安装了相应的加载包。

与为 mingw 选择的构建方法无关,安装路径与使用 VC-* 目标构建时使用的路径类似,只是如果不可能使用这里提到的回退(通常是在 Linux 上交叉编译时),路径如下:

对于 mingw:

    PREFIX:      C:/Program Files (x86)/OpenSSL
    OPENSSLDIR   C:/Program Files (x86)/Common Files/SSL

对于 mingw64:

    PREFIX:      C:/Program Files/OpenSSL
    OPENSSLDIR   C:/Program Files/Common Files/SSL

链接您的应用
===========

本节适用于所有的 "本机" 构建。

如果你与静态的 OpenSSL 库链接,那么你需要将你的应用程序与 WS2_32.LIB、GDI32.LIB、ADVAPI32.LIB、CRYPT32.LIB 和 USER32.LIB 链接。
那些开发非交互式服务程序的人可能会担心与 GDI32.LIB 和 USER32.LIB 的链接,因为它们与交互式桌面有正义感,而交互式桌面是服务进程无法使用的。
这个工具包是为了检测它当前在哪个上下文中执行,是 GUI、控制台应用程序还是服务,并采取相应的行动,即是否实际进行 GUI 调用。
此外,那些希望 /DELAYLOAD:GDI32.DLL 和 /DELAYLOAD:USER32.DLL 并将其从服务进程中保留下来的人,应该考虑从 .exe 镜像中实现和导出 _OPENSSL_isservice,而不是依赖 USER32.DLL。
例如,在 Windows Vista 及以后的系统中,你可以:

    __declspec(dllexport) __cdecl BOOL _OPENSSL_isservice(void)
    {   DWORD sess;
        if (ProcessIdToSessionId(GetCurrentProcessId(),&sess))
            return sess==0;
        return FALSE;
    }

如果您与 OpenSSL .DLLs 链接,那么您需要在您的应用程序代码中包含一个小的 "shim" 片段,它在 OpenSSL BIO 层和您的编译器运行时提供了粘合剂。
更多详情请参见 OPENSSL_Applink 手册页面。

Cygwin,"托管" 环境
==================

Cygwin 在 Windows 子系统之上实现了一个 Posix/Unix 运行时系统(cygwin1.dll),并提供了一个 bash shell 和 GNU 工具环境。
因此,使用 Cygwin 开发的 OpenSSL 与 Unix 程序几乎完全相同。

要使用 Cygwin 构建 OpenSSL,你需要:

* 安装Cygwin (见 https://cygwin.com/)

* 安装 Cygwin Perl 并确保它在路径中。记住,至少需要 5.10.0 版本。

* 运行 Cygwin bash shell

除此之外,请按照 install 中的 Unix 说明进行操作。

注意: "make test" 和正常的文件操作可能会在挂载为文本的目录中失败(例如:mount -t c:\somewhere /home),这是由于 Cygwin 剥离了回车符。
为了避免这种情况,确保使用二进制挂载,例如:mount -b c:\somewhere /home。

猜你喜欢

转载自blog.csdn.net/u012088909/article/details/106450612