LoginSignup
4
5

More than 1 year has passed since last update.

Visual Studio 2019 における OpenSSL のビルド

Last updated at Posted at 2020-07-12

はじめに

  • Windows 環境(Visual Studio 2019)で、OpenSSL をビルドする際の手順を記載します。
  • また、今回、64bit のスタティックライブラリをビルドする場合の例を記載します。
    • ※バージョンは openssl 1.1.1l を対象としています。

ビルド手順

OpenSSLのダウンロード

  1. OpenSSL のダウンロードページ からソースを取得します。
    • 「openssl-1.1.1l.tar.gz」をダウンロードします
  2. tar ファイルを解凍します。
※C:\opensslに配置した openssl-1.1.1l.tar.gz を解凍した例

cd C:\openssl
tar -xvf .\openssl-1.1.1l.tar.gz

ビルドの事前準備

続いて、解凍フォルダの「NOTES.WIN」に従い、ビルドに必要な各種ツールをインストールします。

  • Perl
    • 他の方の記事でも紹介されていますが、個人的には「Strawberry Perl」の方がお勧めです。
      • ActiveState Perlですと、後述の Configureで「Can't locate Win32/Console.pm in @INC (you may need to install the Win32::Console module)」とのエラーが生じ、 「Win32::Console module」の追加インストールが別途必要なようです。
  • NASM
※ NOTES.WINより引用

 Visual C++ builds, aka VC-*
 ==============================

 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, aka 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.

OpenSSL のビルド

Visual Studio 用開発者コマンド プロンプトの起動

Visual Studio 用開発者コマンド プロンプトを起動します。手順は、Visual Studio 用開発者コマンド プロンプトで紹介されています。

  • 注意点

ビルドターゲットの Configure

Perl を用いてビルドターゲットを設定します。以下の例では、Windows 用 64bit スタティックライブラリをビルドするよう設定しています。

C:\openssl>cd openssl-1.1.1l
C:\openssl\openssl-1.1.1l>perl Configure VC-WIN64A no-asm no-shared
Configuring OpenSSL version 1.1.1l (0x101010cfL) for VC-WIN64A
Using os-specific seed configuration
Creating configdata.pm
Creating makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************
  • 補足
    • Configure では以下のように option が幾つか用意されています。 Compilation and Installation のページにも紹介されています。
オプション 説明
no-asm C言語 ルーティンに従う
no-shared スタティックライブラリのみ生成する
--prefix=XXX インストール先の指定(ビルド物やhファイル等)
--openssldir=XXX インストール先の指定

ビルド

Visual Studio に同梱されている「NMAKE」でビルドおよびインストールを実行します。実行後は、以下のスタティックライブラリが生成されます。

  • libcrypto.lib
  • libssl.lib
# ビルド
C:\openssl\openssl-1.1.1l>nmake
...

# ビルドモジュールのインストール
C:\openssl\openssl-1.1.1l>nmake install

補足: OpenSSL のスタティックリンク

OpenSSLの「NOTES.WIN」より、libcrypto.lib、libssl.libをスタティックリンクする際、以下のスタティックライブラリも必要です。

  • ws2_32.lib
  • gdi32.lib
  • advapi32.lib
  • crypt32.lib
  • user32.lib
※ NOTES.WINより引用

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

参考資料

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5