Compiling OpenSSL with MinGW: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
m (Corrected lines)
 
(3 intermediate revisions by 3 users not shown)
Line 5: Line 5:
Qt 5 / QtWebkit can make use of OpenSSL, which MinGW distributions do not ship.
Qt 5 / QtWebkit can make use of OpenSSL, which MinGW distributions do not ship.


== Pre-built packages ==
==Pre-built packages==


The [http://slproweb.com/products/Win32OpenSSL.html Win32OpenSSL project] provides pre-compiled libraries for both 32 and 64 bit. However, these depend on the Microsoft Visual C++ 2008 runtime being installed.
The [http://slproweb.com/products/Win32OpenSSL.html Win32OpenSSL project] provides pre-compiled libraries for both 32 and 64 bit. However, these depend on the Microsoft Visual C++ 2008 runtime being installed.
Line 11: Line 11:
Inside [[MSYS2]] shell, pre-built openssl can be obtained from MSYS2 repo, with this command: pacman -S openssl
Inside [[MSYS2]] shell, pre-built openssl can be obtained from MSYS2 repo, with this command: pacman -S openssl


== Compiling on your own ==
==Compiling on your own==


=== Requirements ===
===Requirements===


* Either use MSYS, or use [[MSYS2]] :  
*Either use MSYS, or use [[MSYS2]] :  
** MSYS shell command prompt (an sh shell + some UNIX tools, get it from http://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.11/MSYS-1.0.11.exe/download?use_mirror=garr. It's also an (optional) part of mingw.org installer). Install it in C:drive in "msys" folder.
**MSYS shell command prompt (an sh shell + some UNIX tools, get it from http://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.11/MSYS-1.0.11.exe/download?use_mirror=garr. It's also an (optional) part of mingw.org installer). Install it in C:drive in "msys" folder.
** [[MSYS2]] shell command prompt, it can be obtained from https://msys2.github.io/ Install it in C:drive in "msys2" folder.
**[[MSYS2]] shell command prompt, it can be obtained from https://msys2.github.io/ Install it in C:drive in "msys2" folder.
* Working MinGW, or MinGW-w64 toolchain:
*Working MinGW, or MinGW-w64 toolchain:
** Either get & load MinGW, or, get & load MinGW-w64 toolchains (from their respective project website), or, use "MinGW-w64" toolchains from MSYS2 repo, inside the MSYS2-shell.
**Either get & load MinGW, or, get & load MinGW-w64 toolchains (from their respective project website), or, use "MinGW-w64" toolchains from MSYS2 repo, inside the MSYS2-shell.
** NOTE: Do not use (or try to avoid using) different type of toolchains for building different sub-components for the same/main project, when targeted for same platform/OS. If you are using MinGW-w64 based toolchains from MSYS2\mingw32 or MSYS2\mingw64, then for main project & all sub-components, use same MSYS2 toolchains. If you are using MinGW toolchain, then for all of your sub-components & main project, use same MinGW toolchain. If you are using MinGW-w64 toolchains from "MinGW-builds", then for all sub-components & main project, use same MinGW-builds toolchains.
**NOTE: Do not use (or try to avoid using) different type of toolchains for building different sub-components for the same/main project, when targeted for same platform/OS. If you are using MinGW-w64 based toolchains from MSYS2\mingw32 or MSYS2\mingw64, then for main project & all sub-components, use same MSYS2 toolchains. If you are using MinGW toolchain, then for all of your sub-components & main project, use same MinGW toolchain. If you are using MinGW-w64 toolchains from "MinGW-builds", then for all sub-components & main project, use same MinGW-builds toolchains.


=== How to build ===
===How to build===


* Download latest+stable [https://www.openssl.org/ OpenSSL] (You must use HTTPS secure encrypted connection to obtain source file) from https://www.openssl.org/source (e.g. openssl-1.0.1c.tar.gz)
*Download latest+stable [https://www.openssl.org/ OpenSSL] (You must use HTTPS secure encrypted connection to obtain source file) from https://www.openssl.org/source (e.g. openssl-1.0.1c.tar.gz)
* Either start MSYS-shell, or start MSYS2-shell:
*Either start MSYS-shell, or start MSYS2-shell:
** Start a MSYS shell command prompt (C:.0\msys.bat)
**Start a MSYS shell command prompt (C:.0\msys.bat)
** Or, start MSYS2 shell command prompt (C:2\msys2_shell.bat)
**Or, start MSYS2 shell command prompt (C:2\msys2_shell.bat)
*** See inside this [[MSYS2]] page, how to prepare MSYS2 with build/compile related toolchains, tools & dependencies
***See inside this [[MSYS2]] page, how to prepare MSYS2 with build/compile related toolchains, tools & dependencies


* Extract source tar.gz using MSYS tar or MSYS2 tar (and ignore the symlink warnings)
*Extract source tar.gz using MSYS tar or MSYS2 tar (and ignore the symlink warnings)
** ''don't use 7zip or other apps, since they fail to set up any symlinks! tar will also complain about symlinks, but compilation will still succeed.''
**''don't use 7zip or other apps, since they fail to set up any symlinks! tar will also complain about symlinks, but compilation will still succeed.''
 
*Unzip/decompress source:


* Unzip/decompress source:
<code>
<code>
$ tar xvzf openssl-1.0.1c.tar.gz
$ tar xvzf openssl-1.0.1c.tar.gz
Line 39: Line 40:
</code>
</code>


* Check that gcc is in PATH, otherwise add it: change below command to match with your-side directory's exact name & letter-case & location:
*Check that gcc is in PATH, otherwise add it: change below command to match with your-side directory's exact name & letter-case & location:
** If using MinGW-builds toolchain (which is usually located outside of MSYS or MSYS2), then execute this in MSYS or in MSYS2:
**If using MinGW-builds toolchain (which is usually located outside of MSYS or MSYS2), then execute this in MSYS or in MSYS2:
 
<code>
<code>
$ export PATH="/c/Mingw-builds/bin:$PATH"
$ export PATH="/c/Mingw-builds/bin:$PATH"
</code>
</code>
** If using MSYS shell, and if you have installed MinGW toolchain into C:32 directory, then execute this:
 
**If using MSYS shell, and if you have installed MinGW toolchain into C:32 directory, then execute this:
 
<code>
<code>
$ export PATH="/c/mingw32/bin:$PATH"
$ export PATH="/c/mingw32/bin:$PATH"
</code>
</code>
** If using MSYS2 shell, execute this, if you are building for 32bit:
 
**If using MSYS2 shell, execute this, if you are building for 32bit:
 
<code>
<code>
$ export PATH="/c/msys2/mingw32/bin:$PATH"
$ export PATH="/c/msys2/mingw32/bin:$PATH"
#or if using 64-bit MSYS2
$ export PATH="/c/msys64/mingw32/bin:$PATH"
</code>
</code>
** If using MSYS2 shell, execute this, if you are building for 64bit:
 
**If using MSYS2 shell, execute this, if you are building for 64bit:
 
<code>
<code>
$ export PATH="/c/msys2/mingw64/bin:$PATH"
$ export PATH="/c/msys32/mingw64/bin:$PATH"
#or if using 64-bit MSYS2
 
$ export PATH="/c/msys64/mingw64/bin:$PATH"
 
</code>
</code>


* for MinGW (32 bit) do:
*Check that you have your PATH correctly setup
<syntaxhighlight lang="shell">
# should point to a mingw distribution of gcc
 
$ which gcc
/c/msys64/mingw32/bin/gcc
</syntaxhighlight>
 
*for MinGW (32 bit) do:
 
<code>
<code>
$ ./Configure --prefix=$PWD/dist no-idea no-mdc2 no-rc5 shared mingw
$ ./Configure --prefix=$PWD/dist no-idea no-mdc2 no-rc5 shared mingw
</code>
</code>


* for MinGW-w64 do:
*for MinGW-w64 do:
 
<code>
<code>
$ ./Configure --prefix=$PWD/dist no-idea no-mdc2 no-rc5 shared mingw64
$ ./Configure --prefix=$PWD/dist no-idea no-mdc2 no-rc5 shared mingw64
</code>
</code>


* Compile & install:
*Compile & install:
 
<code>
<code>
$ make depend && make && make install
$ make depend && make && make install
</code>
</code>


== Errors ==
==Errors==
 
*If you run into


* If you run into
<code>
<code>
perl asm/sha1-x86_64.pl mingw64 > sha1-x86_64.s
perl asm/sha1-x86_64.pl mingw64 > sha1-x86_64.s
Line 85: Line 113:
sha1-x86_64.s:1824: Warning: end of file not at end of a line; newline inserted
sha1-x86_64.s:1824: Warning: end of file not at end of a line; newline inserted
sha1-x86_64.s:2183: Error: number of operands mismatch for `rol'
sha1-x86_64.s:2183: Error: number of operands mismatch for `rol'
make[2]: '''* [sha1-x86_64.o] Error 1
make[2]: '''* [sha1-x86_64.o] Error 1'''
make[2]: Leaving directory `/d/dev/tmp/openssl-1.0.1c/crypto/sha'
make[2]: Leaving directory `/d/dev/tmp/openssl-1.0.1c/crypto/sha'
make[1]:'''* [subdirs] Error 1
make[1]:'''* [subdirs] Error 1'''
make[1]: Leaving directory `/d/dev/tmp/openssl-1.0.1c/crypto'
make[1]: Leaving directory `/d/dev/tmp/openssl-1.0.1c/crypto'
make: '''* [build_crypto] Error 1
make: '''* [build_crypto] Error 1'''
</code>
</code>


''' check out http://openssl.6102.n7.nabble.com/Compile-error-with-MinGW-w64-td36657.html
''' check out http://openssl.6102.n7.nabble.com/Compile-error-with-MinGW-w64-td36657.html'''
'''* Use perl inside MSYS or inside MSYS2
'''* Use perl inside MSYS or inside MSYS2'''
'''* or change crypto/perlasm/x86_64-xlate.pl as mentioned in the e-mail thread.
'''* or change crypto/perlasm/x86_64-xlate.pl as mentioned in the e-mail thread.'''
 
==Using it==
 
*If you are using cmd.exe (Cmd-shell), then: add the bin, include, lib folders to your compilation environment:
 
<code>C:\> set PATH=PATH;C:\openssl–1.0.1c\dist\bin</code>
 
<code>C:\> set INCLUDE=INCLUDE;C:\openssl–1.0.1c\dist\include</code>
 
<code>C:\> set LIB=LIB;C:\openssl–1.0.1c\dist\lib</code>
 
*If you are using MSYS2/MSYS-shell, then: add the bin, include, lib folders to your compilation environment:
 
<code>$ export PATH="$PATH:/c/openssl-1.0.1c/dist/bin"</code>


== Using it ==
<code>$ export INCLUDE="$INCLUDE:/c/openssl-1.0.1c/dist/include"</code>


* If you are using cmd.exe (Cmd-shell), then: add the bin, include, lib folders to your compilation environment:
<code>$ export LIB="$LIB:/c/openssl-1.0.1c/dist/lib"</code>
<code>
C:gt; set PATH=PATH;C:–1.0.1c\dist\bin
C:gt; set INCLUDE=INCLUDE;C:–1.0.1c\dist\include
C:gt; set LIB=LIB;C:–1.0.1c\dist\lib
</code>
* If you are using MSYS2/MSYS-shell, then: add the bin, include, lib folders to your compilation environment:
<code>
$ export PATH="$PATH:/c/openssl-1.0.1c/dist/bin"
$ export INCLUDE="$INCLUDE:/c/openssl-1.0.1c/dist/include"
$ export LIB="$LIB:/c/openssl-1.0.1c/dist/lib"
</code>


When you now run Qt's configure.exe openssl should be detected, and Qt links against the libraries.
When you now run Qt's configure.exe openssl should be detected, and Qt links against the libraries.

Latest revision as of 04:33, 28 December 2021

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

Qt 5 / QtWebkit can make use of OpenSSL, which MinGW distributions do not ship.

Pre-built packages

The Win32OpenSSL project provides pre-compiled libraries for both 32 and 64 bit. However, these depend on the Microsoft Visual C++ 2008 runtime being installed.

Inside MSYS2 shell, pre-built openssl can be obtained from MSYS2 repo, with this command: pacman -S openssl

Compiling on your own

Requirements

  • Either use MSYS, or use MSYS2 :
  • Working MinGW, or MinGW-w64 toolchain:
    • Either get & load MinGW, or, get & load MinGW-w64 toolchains (from their respective project website), or, use "MinGW-w64" toolchains from MSYS2 repo, inside the MSYS2-shell.
    • NOTE: Do not use (or try to avoid using) different type of toolchains for building different sub-components for the same/main project, when targeted for same platform/OS. If you are using MinGW-w64 based toolchains from MSYS2\mingw32 or MSYS2\mingw64, then for main project & all sub-components, use same MSYS2 toolchains. If you are using MinGW toolchain, then for all of your sub-components & main project, use same MinGW toolchain. If you are using MinGW-w64 toolchains from "MinGW-builds", then for all sub-components & main project, use same MinGW-builds toolchains.

How to build

  • Download latest+stable OpenSSL (You must use HTTPS secure encrypted connection to obtain source file) from https://www.openssl.org/source (e.g. openssl-1.0.1c.tar.gz)
  • Either start MSYS-shell, or start MSYS2-shell:
    • Start a MSYS shell command prompt (C:.0\msys.bat)
    • Or, start MSYS2 shell command prompt (C:2\msys2_shell.bat)
      • See inside this MSYS2 page, how to prepare MSYS2 with build/compile related toolchains, tools & dependencies
  • Extract source tar.gz using MSYS tar or MSYS2 tar (and ignore the symlink warnings)
    • don't use 7zip or other apps, since they fail to set up any symlinks! tar will also complain about symlinks, but compilation will still succeed.
  • Unzip/decompress source:
$ tar xvzf openssl-1.0.1c.tar.gz
$ cd openssl-1.0.1c
  • Check that gcc is in PATH, otherwise add it: change below command to match with your-side directory's exact name & letter-case & location:
    • If using MinGW-builds toolchain (which is usually located outside of MSYS or MSYS2), then execute this in MSYS or in MSYS2:
$ export PATH="/c/Mingw-builds/bin:$PATH"
    • If using MSYS shell, and if you have installed MinGW toolchain into C:32 directory, then execute this:
$ export PATH="/c/mingw32/bin:$PATH"
    • If using MSYS2 shell, execute this, if you are building for 32bit:
$ export PATH="/c/msys2/mingw32/bin:$PATH"
#or if using 64-bit MSYS2

$ export PATH="/c/msys64/mingw32/bin:$PATH"
    • If using MSYS2 shell, execute this, if you are building for 64bit:
$ export PATH="/c/msys32/mingw64/bin:$PATH"
#or if using 64-bit MSYS2

$ export PATH="/c/msys64/mingw64/bin:$PATH"
  • Check that you have your PATH correctly setup
# should point to a mingw distribution of gcc

$ which gcc
/c/msys64/mingw32/bin/gcc
  • for MinGW (32 bit) do:
$ ./Configure --prefix=$PWD/dist no-idea no-mdc2 no-rc5 shared mingw
  • for MinGW-w64 do:
$ ./Configure --prefix=$PWD/dist no-idea no-mdc2 no-rc5 shared mingw64
  • Compile & install:
$ make depend && make && make install

Errors

  • If you run into
perl asm/sha1-x86_64.pl mingw64 > sha1-x86_64.s
gcc -I.. -I../.. -I../modes -I../asn1 -I../evp -I../../include -D_WINDLL -DOPENSSL_PIC -DOPENSSL_TH
READS -D_MT -DDSO_WIN32 -DL_ENDIAN -O3 -Wall -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE -DOPENSSL_IA
32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM-
DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -c -o sha1-x86_
64.o sha1-x86_64.s
sha1-x86_64.s: Assembler messages:
sha1-x86_64.s:1824: Warning: end of file not at end of a line; newline inserted
sha1-x86_64.s:2183: Error: number of operands mismatch for `rol'
make[2]: '''* [sha1-x86_64.o] Error 1'''
make[2]: Leaving directory `/d/dev/tmp/openssl-1.0.1c/crypto/sha'
make[1]:'''* [subdirs] Error 1'''
make[1]: Leaving directory `/d/dev/tmp/openssl-1.0.1c/crypto'
make: '''* [build_crypto] Error 1'''

check out http://openssl.6102.n7.nabble.com/Compile-error-with-MinGW-w64-td36657.html * Use perl inside MSYS or inside MSYS2 * or change crypto/perlasm/x86_64-xlate.pl as mentioned in the e-mail thread.

Using it

  • If you are using cmd.exe (Cmd-shell), then: add the bin, include, lib folders to your compilation environment:
C:\> set PATH=PATH;C:\openssl1.0.1c\dist\bin
C:\> set INCLUDE=INCLUDE;C:\openssl1.0.1c\dist\include
C:\> set LIB=LIB;C:\openssl1.0.1c\dist\lib
  • If you are using MSYS2/MSYS-shell, then: add the bin, include, lib folders to your compilation environment:
$ export PATH="$PATH:/c/openssl-1.0.1c/dist/bin"
$ export INCLUDE="$INCLUDE:/c/openssl-1.0.1c/dist/include"
$ export LIB="$LIB:/c/openssl-1.0.1c/dist/lib"

When you now run Qt's configure.exe openssl should be detected, and Qt links against the libraries.