question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question] Compiling OpenSSL with MinGW on Windows

See original GitHub issue

How can I compile OpenSSL with conan and MinGW 8.2 on Windows 10?

I’m using MinGW 8.2.0 from STL compilation and conan 1.20.1 on Windows 10.

I’m trying to install websocketpp that has OpenSSL 1.1.1c as dependency. Console outputs the following:

PS C:\Users\User\Documents\Sources\MRT\Development> conan install . --build=missing
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=8.2
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

WARN: websocketpp/0.8.1@bincrafters/stable: requirement asio/1.12.0@bincrafters/stable overridden by your conanfile to asio/1.13.0@bincrafters/stable
OpenSSL/1.1.1c@conan/stable: Not found in local cache, looking in remotes...
OpenSSL/1.1.1c@conan/stable: Trying with 'conan-center'...
Downloading conanmanifest.txt: 100%|##########| 58.0/58.0 [00:00<00:00, 17.7kB/s]
Downloading conanfile.py: 100%|##########| 28.7k/28.7k [00:00<00:00, 111kB/s]
OpenSSL/1.1.1c@conan/stable: Downloaded recipe revision 0
conanfile.txt: Installing package
Requirements
    OpenSSL/1.1.1c@conan/stable from 'conan-center' - Downloaded
    asio/1.13.0@bincrafters/stable from 'conan-center' - Cache
    fmt/6.0.0@bincrafters/stable from 'conan-center' - Cache
    paho-c/1.3.0@conan/stable from 'conan-center' - Cache
    pugixml/1.10@bincrafters/stable from 'conan-center' - Cache
    rapidjson/1.1.0@bincrafters/stable from 'conan-center' - Cache
    spdlog/1.4.2@bincrafters/stable from 'conan-center' - Cache
    sqlite3/3.29.0 from 'conan-center' - Cache
    websocketpp/0.8.1@bincrafters/stable from 'bincrafters' - Cache
    zlib/1.2.11@conan/stable from 'conan-center' - Cache
Packages
    OpenSSL/1.1.1c@conan/stable:0fa24fc17987c7ebda4490aaf810b500f741dab6 - Build
    asio/1.13.0@bincrafters/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache
    fmt/6.0.0@bincrafters/stable:d2e9f0427a9f423abdfdcd9fc1fca32c78f3be27 - Cache
    paho-c/1.3.0@conan/stable:11970fe766f2003618a4453bd3b5a3990f025a65 - Cache
    pugixml/1.10@bincrafters/stable:d2e9f0427a9f423abdfdcd9fc1fca32c78f3be27 - Cache
    rapidjson/1.1.0@bincrafters/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache
    spdlog/1.4.2@bincrafters/stable:a1605c08cfb1e7a1f94058c08792d89866f7ebbd - Build
    sqlite3/3.29.0:8b8ab72be77c9228fea3280f90348dfbde80f9d0 - Cache
    websocketpp/0.8.1@bincrafters/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Download
    zlib/1.2.11@conan/stable:e50fc893ef691a3c18ad21536d7cf203bc81bd95 - Cache
Build requirements
    nasm/2.13.01@conan/stable from 'conan-center' - Cache
Build requirements packages
    nasm/2.13.01@conan/stable:456f15897172eef340fcbac8a70811f2beb26a93 - Cache

asio/1.13.0@bincrafters/stable: Already installed!
fmt/6.0.0@bincrafters/stable: Already installed!
nasm/2.13.01@conan/stable: Already installed!
nasm/2.13.01@conan/stable: Using nasm-2.13.01 version
paho-c/1.3.0@conan/stable: Already installed!
pugixml/1.10@bincrafters/stable: Already installed!
rapidjson/1.1.0@bincrafters/stable: Already installed!
sqlite3/3.29.0: Already installed!
zlib/1.2.11@conan/stable: Already installed!
OpenSSL/1.1.1c@conan/stable: Applying build-requirement: nasm/2.13.01@conan/stable
OpenSSL/1.1.1c@conan/stable: Configuring sources in C:\Users\User\.conan\data\OpenSSL\1.1.1c\conan\stable\source
Downloading openssl-1.1.1c.tar.gz: 100%|##########| 8.45M/8.45M [00:20<00:00, 437kB/s]

OpenSSL/1.1.1c@conan/stable: Copying sources to build folder
OpenSSL/1.1.1c@conan/stable: Building your package in C:\Users\User\.conan\data\OpenSSL\1.1.1c\conan\stable\build\0fa24fc17987c7ebda4490aaf810b500f741dab6
OpenSSL/1.1.1c@conan/stable: Generator txt created conanbuildinfo.txt
OpenSSL/1.1.1c@conan/stable: Calling build()
OpenSSL/1.1.1c@conan/stable: using target: mingw-conan-Release-Windows-x86_64-gcc-8.2 -> mingw64
OpenSSL/1.1.1c@conan/stable: my %targets = (
    "mingw-conan-Release-Windows-x86_64-gcc-8.2" => {
        inherit_from => [ "mingw64" ],
        cflags => add("-m64 -O3 -s"),
        cxxflags => add("-m64 -O3 -s"),
        defines => add("NDEBUG"),
        includes => add("C:/Users/User/.conan/data/zlib/1.2.11/conan/stable/package/e50fc893ef691a3c18ad21536d7cf203bc81bd95/include"),
        lflags => add("-m64"),




    },
);

OpenSSL/1.1.1c@conan/stable: ['"mingw-conan-Release-Windows-x86_64-gcc-8.2"', 'no-shared', '--prefix=/c/users/user/.conan/data/openssl/1.1.1c/conan/stable/package/0fa24fc17987c7ebda4490aaf810b500f741dab6', '--openssldir=/c/users/user/.conan/data/openssl/1.1.1c/conan/stable/package/0fa24fc17987c7ebda4490aaf810b500f741dab6/res', 'no-unit-test', 'PERL=perl', 'no-tests', '--release', '--with-zlib-include="C:/Users/User/.conan/data/zlib/1.2.11/conan/stable/package/e50fc893ef691a3c18ad21536d7cf203bc81bd95/include"', '--with-zlib-lib="C:/Users/User/.conan/data/zlib/1.2.11/conan/stable/package/e50fc893ef691a3c18ad21536d7cf203bc81bd95/lib/zlib.lib"']
OpenSSL/1.1.1c@conan/stable:
OpenSSL/1.1.1c@conan/stable: ERROR: Package '0fa24fc17987c7ebda4490aaf810b500f741dab6' build failed
OpenSSL/1.1.1c@conan/stable: WARN: Build folder C:\Users\User\.conan\data\OpenSSL\1.1.1c\conan\stable\build\0fa24fc17987c7ebda4490aaf810b500f741dab6
ERROR: OpenSSL/1.1.1c@conan/stable: Error in build() method, line 552
        self._make()
while calling '_make', line 502
        self.run('{perl} ./Configure {args}'.format(perl=self._perl, args=args), win_bash=self._win_bash)
        ConanException: Cannot recognize the Windows subsystem, install MSYS2/cygwin or specify a build_require to apply it.
PS C:\Users\User\Documents\Sources\MRT\Development>

I have tried changing build_requires from default profile settings to use cygwin_installer/msys2_installer for OpenSSL only.

As shown here:

.conan/profiles/default:

[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=8.2
build_type=Release
[options]
[build_requires]
#OpenSSL*: msys2_installer/20161025@bincrafters/stable
#OpenSSL*: cygwin_installer/2.9.0@bincrafters/stable
[env]

But I get some kind of error with some Win32API headers, I have attached a file with the output. cygwin output.txt

May I ask how can I use this package to be used with websocketpp?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
SSE4commented, Nov 15, 2019

seems like similar to https://github.com/openssl/openssl/issues/2979

This happens if you attempt to build OpenSSL using the msys gcc compiler rather than the mingw compiler

so, it’s probably wrong GCC instance was picked up. could you try to specify CC/CXX environment variables within your profile pointing to the right GCC executables (from https://nuwen.net/mingw.html)

0reactions
leyewencommented, Jan 8, 2020

NEW UPDATE: I deep research this issues. Finally, sum up the experience:

First, Cannot recognize the Windows subsystem, install MSYS2/cygwin :

ERROR: openssl/1.1.1d: Error in build() method, line 529
	self._make()
while calling '_make', line 477
	self.run('{perl} ./Configure {args}'.format(perl=self._perl, args=args), win_bash=self._win_bash)
	ConanException: Cannot recognize the Windows subsystem, install MSYS2/cygwin or specify a build_require to apply it.

add msys2 to conanfile.py

    def build_requirements(self):
        # useful for example for conditional build_requires
        if tools.os_info.is_windows:
            if not self._win_bash:
                self.build_requires("strawberryperl/5.30.0.1")
            if not self.options.no_asm and not tools.which("nasm"):
                self.build_requires("nasm/2.14")
            # add msys2 require
            if "CONAN_BASH_PATH" not in os.environ:
                self.build_requires("msys2/20190524")

We need msys2 support bash in windows.

Second, dso_win32 error: If use msys2/20190524 only environment will due to this error. Why is this happening? When use msys2, conanfile.py identify the system status as mingw64.

# line 174
is_cygwin = self.settings.get_safe("os.subsystem") == "cygwin" # default false
......
# line 226
"Windows-x86_64-gcc": "Cygwin-x86_64" if is_cygwin else "mingw64" # result mingw64

read https://mta.openssl.org/pipermail/openssl-commits/2015-March/000733.html openssl: Cygwin to use DSO_FLFCN and mingw to use DSO_WIN32. And msys2 is based on modern Cygwin. It recognized is_cygwin as false, but building with msys2(Cygwin) by using mingw64 mode!

1 option If only target msys2, you need to tell your profile use cygwin subsystem:

os.subsystem=cygwin

building with msys2 by using cygwin mode.

2 option Add mingw build_requires to your profile:

openssl/1.1.1d:msys2/20190524
openssl/1.1.1d:mingw_installer/1.0@conan/stable

or

openssl/1.1.1d:msys2/20190524, mingw_installer/1.0@conan/stable

building with mingw by using mingw mode.

3 option Use msys2 subsystem mingw64: msys2 install mingw-w64-x86_64-toolchain run C:\.conan\f16a5d\1\bin\msys2.exe pacman -S mingw-w64-x86_64-toolchain --noconfirm build profile add target toolchain=x86_64-w64-mingw32

toolchain=x86_64-w64-mingw32
target_host=x86_64-w64-mingw32
cc_compiler=gcc
cxx_compiler=g++

[env]
CONAN_CMAKE_FIND_ROOT_PATH=$toolchain
CC=$target_host-$cc_compiler
CXX=$target_host-$cxx_compiler

4 option Update is_cygwin logical judgment.

The above configurations have been tested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to build OpenSSL with MinGW in Windows? [closed]
To build OpenSSL, you need a working Perl installation. Download OpenSSL from its official website and decompress the archive. Windows 32/64 ...
Read more >
Compiling OpenSSL with MinGW - Qt Wiki
The Win32OpenSSL project provides pre-compiled libraries for both 32 and 64 bit. However, these depend on the Microsoft Visual C++ 2008 runtime ...
Read more >
Compilation and Installation - OpenSSLWiki
OpenSSL uses a custom build system to configure the library. Configuration will allow the library to set up the recursive makefiles from ...
Read more >
web.mit.edu/Ghudson/dev/third/openssl/INSTALL.W32
WCE] Heres a few comments about building OpenSSL in Windows environments. ... C (Cygwin or MinGW) If you are compiling from a tarball...
Read more >
Issue #1476: Linux to Windows crosscompile mingw64 openssl
I am trying to cross compile strongSwan 5.4.0 from Linux for Window. ... problem with the source? libcrypto does not exist in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found