NOTES-Windows.txt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. NOTES FOR WINDOWS PLATFORMS
  2. ===========================
  3. (This file, like the others, is in "markdown" format, but has a ".txt"
  4. extension to make it easier to view/edit on Windows.)
  5. There are various options to build and run OpenSSL on the Windows platforms.
  6. "Native" OpenSSL uses the Windows APIs directly at run time.
  7. To build a native OpenSSL you can either use:
  8. Microsoft Visual C++ (MSVC) C compiler on the command line
  9. or
  10. MinGW cross compiler
  11. run on the GNU-like development environment MSYS2
  12. or run on Linux or Cygwin
  13. "Hosted" OpenSSL relies on an external POSIX compatibility layer
  14. for building (using GNU/Unix shell, compiler, and tools) and at run time.
  15. For this option you can use Cygwin.
  16. Visual C++ native builds, aka VC-*
  17. =====================================
  18. Requirement details
  19. -------------------
  20. In addition to the requirements and instructions listed in INSTALL.md,
  21. these are required as well:
  22. - Perl.
  23. We recommend Strawberry Perl, available from <http://strawberryperl.com/>
  24. Please read NOTES.PERL for more information, including the use of CPAN.
  25. An alternative is ActiveState Perl, <https://www.activestate.com/ActivePerl>
  26. for which you may need to explicitly build the Perl module Win32/Console.pm
  27. via <https://platform.activestate.com/ActiveState> and then download it.
  28. - Microsoft Visual C compiler.
  29. Since these are proprietary and ever-changing we cannot test them all.
  30. Older versions may not work. Use a recent version wherever possible.
  31. - Netwide Assembler (NASM), available from <https://www.nasm.us>
  32. Note that NASM is the only supported assembler.
  33. Quick start
  34. -----------
  35. 1. Install Perl
  36. 2. Install NASM
  37. 3. Make sure both Perl and NASM are on your %PATH%
  38. 4. Use Visual Studio Developer Command Prompt with administrative privileges,
  39. choosing one of its variants depending on the intended architecture.
  40. Or run "cmd" and execute "vcvarsall.bat" with one of the options x86,
  41. x86_amd64, x86_arm, x86_arm64, amd64, amd64_x86, amd64_arm, or amd64_arm64.
  42. This sets up the environment variables needed for nmake.exe, cl.exe, etc.
  43. See also
  44. <https://docs.microsoft.com/cpp/build/building-on-the-command-line>
  45. 5. From the root of the OpenSSL source directory enter
  46. perl Configure VC-WIN32 if you want 32-bit OpenSSL or
  47. perl Configure VC-WIN64A if you want 64-bit OpenSSL or
  48. perl Configure to let Configure figure out the platform
  49. 6. nmake
  50. 7. nmake test
  51. 8. nmake install
  52. For the full installation instructions, or if anything goes wrong at any stage,
  53. check the INSTALL.md file.
  54. Installation directories
  55. ------------------------
  56. The default installation directories are derived from environment
  57. variables.
  58. For VC-WIN32, the following defaults are use:
  59. PREFIX: %ProgramFiles(86)%\OpenSSL
  60. OPENSSLDIR: %CommonProgramFiles(86)%\SSL
  61. For VC-WIN64, the following defaults are use:
  62. PREFIX: %ProgramW6432%\OpenSSL
  63. OPENSSLDIR: %CommonProgramW6432%\SSL
  64. Should those environment variables not exist (on a pure Win32
  65. installation for examples), these fallbacks are used:
  66. PREFIX: %ProgramFiles%\OpenSSL
  67. OPENSSLDIR: %CommonProgramFiles%\SSL
  68. ALSO NOTE that those directories are usually write protected, even if
  69. your account is in the Administrators group. To work around that,
  70. start the command prompt by right-clicking on it and choosing "Run as
  71. Administrator" before running 'nmake install'. The other solution
  72. is, of course, to choose a different set of directories by using
  73. --prefix and --openssldir when configuring.
  74. Special notes for Universal Windows Platform builds, aka VC-*-UWP
  75. --------------------------------------------------------------------
  76. - UWP targets only support building the static and dynamic libraries.
  77. - You should define the platform type to "uwp" and the target arch via
  78. "vcvarsall.bat" before you compile. For example, if you want to build
  79. "arm64" builds, you should run "vcvarsall.bat x86_arm64 uwp".
  80. Native OpenSSL built using MinGW
  81. ================================
  82. MinGW offers an alternative way to build native OpenSSL, by cross compilation.
  83. * Usually the build is done on Windows in a GNU-like environment called MSYS2.
  84. MSYS2 provides GNU tools, a Unix-like command prompt,
  85. and a UNIX compatibility layer for applications.
  86. However, in this context it is only used for building OpenSSL.
  87. The resulting OpenSSL does not rely on MSYS2 to run and is fully native.
  88. Requirement details
  89. - MSYS2 shell, from <https://www.msys2.org/>
  90. - Perl, at least version 5.10.0, which usually comes pre-installed with MSYS2
  91. - make, installed using "pacman -S make" into the MSYS2 environment
  92. - MinGW[64] compiler: mingw-w64-i686-gcc and/or mingw-w64-x86_64-gcc.
  93. These compilers must be on your MSYS2 $PATH.
  94. A common error is to not have these on your $PATH.
  95. The MSYS2 version of gcc will not work correctly here.
  96. In the MSYS2 shell do the configuration depending on the target architecture:
  97. ./Configure mingw ...
  98. or
  99. ./Configure mingw64 ...
  100. or
  101. ./Configure ...
  102. for the default architecture.
  103. Apart from that, follow the Unix / Linux instructions in INSTALL.md.
  104. * It is also possible to build mingw[64] on Linux or Cygwin.
  105. In this case configure with the corresponding --cross-compile-prefix= option.
  106. For example
  107. ./Configure mingw --cross-compile-prefix=i686-w64-mingw32- ...
  108. or
  109. ./Configure mingw64 --cross-compile-prefix=x86_64-w64-mingw32- ...
  110. This requires that you've installed the necessary add-on packages for
  111. mingw[64] cross compilation.
  112. Linking your application
  113. ========================
  114. This section applies to all "native" builds.
  115. If you link with static OpenSSL libraries then you're expected to
  116. additionally link your application with WS2_32.LIB, GDI32.LIB,
  117. ADVAPI32.LIB, CRYPT32.LIB and USER32.LIB. Those developing
  118. non-interactive service applications might feel concerned about
  119. linking with GDI32.LIB and USER32.LIB, as they are justly associated
  120. with interactive desktop, which is not available to service
  121. processes. The toolkit is designed to detect in which context it's
  122. currently executed, GUI, console app or service, and act accordingly,
  123. namely whether or not to actually make GUI calls. Additionally those
  124. who wish to /DELAYLOAD:GDI32.DLL and /DELAYLOAD:USER32.DLL and
  125. actually keep them off service process should consider implementing
  126. and exporting from .exe image in question own _OPENSSL_isservice not
  127. relying on USER32.DLL. E.g., on Windows Vista and later you could:
  128. __declspec(dllexport) __cdecl BOOL _OPENSSL_isservice(void)
  129. {
  130. DWORD sess;
  131. if (ProcessIdToSessionId(GetCurrentProcessId(), &sess))
  132. return sess == 0;
  133. return FALSE;
  134. }
  135. If you link with OpenSSL .DLLs, then you're expected to include into
  136. your application code a small "shim" snippet, which provides
  137. the glue between the OpenSSL BIO layer and your compiler run-time.
  138. See also the OPENSSL_Applink manual page.
  139. Hosted OpenSSL built using Cygwin
  140. =================================
  141. Cygwin implements a POSIX/Unix runtime system (cygwin1.dll) on top of the
  142. Windows subsystem and provides a Bash shell and GNU tools environment.
  143. Consequently, a build of OpenSSL with Cygwin is virtually identical to the
  144. Unix procedure.
  145. To build OpenSSL using Cygwin, you need to:
  146. * Install Cygwin, see <https://cygwin.com/>
  147. * Install Cygwin Perl, at least version 5.10.0
  148. and ensure it is in the $PATH
  149. * Run the Cygwin Bash shell
  150. Apart from that, follow the Unix / Linux instructions in INSTALL.md.
  151. NOTE: "make test" and normal file operations may fail in directories
  152. mounted as text (i.e. mount -t c:\somewhere /home) due to Cygwin
  153. stripping of carriage returns. To avoid this ensure that a binary
  154. mount is used, e.g. mount -b c:\somewhere /home.