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.

[bug] Cross compiling with MinGW fails

See original GitHub issue

When cross compiling from Linux to Windows using MinGw Conan tries to use cmake -G "MinGW Makefiles" but CMake MinGW generator isn’t available on Linux.

It worked fine until yesterday (12/8/2022).

Environment Details (include every applicable attribute)

  • Operating System+version: Manjaro Linux, Ubuntu 22.04
  • Compiler+version: MinGW GCC 12.1, MinGW GCC 10
  • Conan version: 1.51.2, 1.50.0, 1.47.0
  • Python version: 3.10.5, 3.10.4

Steps to reproduce (Include if Applicable)

add MinGW profile:

toolchain=/usr/x86_64-w64-mingw32 # Adjust this path
target_host=x86_64-w64-mingw32
cc_compiler=gcc
cxx_compiler=g++

[env]
CONAN_CMAKE_FIND_ROOT_PATH=$toolchain  # Optional, for CMake to find things in that folder
CONAN_CMAKE_SYSROOT=$toolchain  # Optional, if we want to define sysroot
CHOST=$target_host
AR=$target_host-ar
AS=$target_host-as
RANLIB=$target_host-ranlib
CC=$target_host-$cc_compiler
CXX=$target_host-$cxx_compiler
STRIP=$target_host-strip
RC=$target_host-windres

[settings]
# We are cross-building to Windows
os=Windows
arch=x86_64
compiler=gcc

# Adjust to the gcc version of your MinGW package
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Release

create conanfile.txt with a package that fails

libraries that fail to build (for me fmt, glfw and boost failed):

[requires]
fmt/9.0.0

try conan install it with the MinGW profile: conan install . --build=outdated -pr=mingw

get the following error:

Configuration:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=11
os=Windows
[options]
[build_requires]
[env]
AR=x86_64-w64-mingw32-ar
AS=x86_64-w64-mingw32-as
CC=x86_64-w64-mingw32-gcc
CHOST=x86_64-w64-mingw32
CONAN_CMAKE_FIND_ROOT_PATH=/usr/x86_64-w64-mingw32 # Adjust this path  # Optional, for CMake to find things in that folder
CONAN_CMAKE_SYSROOT=/usr/x86_64-w64-mingw32 # Adjust this path  # Optional, if we want to define sysroot
CXX=x86_64-w64-mingw32-g++
RANLIB=x86_64-w64-mingw32-ranlib
RC=x86_64-w64-mingw32-windres
STRIP=x86_64-w64-mingw32-strip
fmt/9.0.0: WARN: Package binary is corrupted, removing: a054a3505f46390899b536d8af712e4a80b781a7
conanfile.txt: Installing package
Requirements
    fmt/9.0.0 from 'conancenter' - Cache
Packages
    fmt/9.0.0:a054a3505f46390899b536d8af712e4a80b781a7 - Build

Cross-build from 'Linux:x86_64' to 'Windows:x86_64'
Installing (downloading, building) binaries...
fmt/9.0.0: WARN: Build folder is dirty, removing it: /home/vm/.conan/data/fmt/9.0.0/_/_/build/a054a3505f46390899b536d8af712e4a80b781a7
fmt/9.0.0: Copying sources to build folder
fmt/9.0.0: Building your package in /home/vm/.conan/data/fmt/9.0.0/_/_/build/a054a3505f46390899b536d8af712e4a80b781a7
fmt/9.0.0: Generator txt created conanbuildinfo.txt
fmt/9.0.0: Calling generate()
fmt/9.0.0: WARN: Using the new toolchains and generators without specifying a build profile (e.g: -pr:b=default) is discouraged and might cause failures and unexpected behavior
fmt/9.0.0: Aggregating env generators
fmt/9.0.0: Calling build()
fmt/9.0.0: CMake command: cmake -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="/home/vm/.conan/data/fmt/9.0.0/_/_/build/a054a3505f46390899b536d8af712e4a80b781a7/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/vm/.conan/data/fmt/9.0.0/_/_/package/a054a3505f46390899b536d8af712e4a80b781a7" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" -DFMT_DOC="False" -DFMT_TEST="False" -DFMT_INSTALL="True" -DFMT_LIB_DIR="lib" -DFMT_OS="True" "/home/vm/.conan/data/fmt/9.0.0/_/_/build/a054a3505f46390899b536d8af712e4a80b781a7/."
CMake Error: Could not create named generator MinGW Makefiles

Generators
  Green Hills MULTI            = Generates Green Hills MULTI files
                                 (experimental, work-in-progress).
* Unix Makefiles               = Generates standard UNIX makefiles.
  Ninja                        = Generates build.ninja files.
  Ninja Multi-Config           = Generates build-<Config>.ninja files.
  Watcom WMake                 = Generates Watcom WMake makefiles.
  CodeBlocks - Ninja           = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
  CodeLite - Ninja             = Generates CodeLite project files.
  CodeLite - Unix Makefiles    = Generates CodeLite project files.
  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
  Kate - Ninja                 = Generates Kate project files.
  Kate - Unix Makefiles        = Generates Kate project files.
  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                               = Generates Sublime Text 2 project files.

fmt/9.0.0: 
fmt/9.0.0: ERROR: Package 'a054a3505f46390899b536d8af712e4a80b781a7' build failed
fmt/9.0.0: WARN: Build folder /home/vm/.conan/data/fmt/9.0.0/_/_/build/a054a3505f46390899b536d8af712e4a80b781a7/build/Release
ERROR: fmt/9.0.0: Error in build() method, line 89
	cmake.configure(variables=cache_entries)
	ConanException: Error 1 while executing cmake -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="/home/vm/.conan/data/fmt/9.0.0/_/_/build/a054a3505f46390899b536d8af712e4a80b781a7/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/vm/.conan/data/fmt/9.0.0/_/_/package/a054a3505f46390899b536d8af712e4a80b781a7" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" -DFMT_DOC="False" -DFMT_TEST="False" -DFMT_INSTALL="True" -DFMT_LIB_DIR="lib" -DFMT_OS="True" "/home/vm/.conan/data/fmt/9.0.0/_/_/build/a054a3505f46390899b536d8af712e4a80b781a7/."

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Enhexcommented, Aug 15, 2022

yeah using two profiles with -pr:b=default -pr:h=linux_to_win64 works

0reactions
JackCarterSmithcommented, Aug 30, 2022

Same problem in there with zlib cross-building Linux->Windows using MinGW 9.3

yeah using two profiles with -pr:b=default -pr:h=linux_to_win64 works

This 2 profiles methods work, I can confirm. Set default as the auto-generated conan config for the “real” host and linux_to_win64 as the target system (aka. Windows with MinGW)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't cross compile C++ files in MinGW properly
I resolved this problem using the -static-libgcc -static-libstdc++ compiler flags to static link all the needed libraries, but Windows still ...
Read more >
644556 – dev-util/mingw64-runtime USE=tools fails bootstrap ...
Per a discussion with ktietz (mingw-w64 developer) in irc.oftc.net/#mingw-w64 when mingw-w64 is compiled as a cross-compiler on linux the ...
Read more >
Error during cross compile with mingw: unknown type name ...
I´m getting the following error when trying to cross compile on linux for windows. Cross compilation worked fine in 1.18.
Read more >
Thread: [Mingw-w64-public] cross-compile fail - SourceForge
This can cause issues if you have conflicting versions of things installed. You are best to install into some prefix outside of your...
Read more >
Cross compilation not working? - Nim forum
Trying to compile with the normal gcc is pointless, it creates the error message because it tries to compile for the host platform,...
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