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。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章