Using a MinGW as tool_requires to build with gcc in Windows

If we had MinGW installed in our environment, we could define a profile like:

  1. [settings]
  2. os=Windows
  3. compiler=gcc
  4. compiler.version=12
  5. compiler.libcxx=libstdc++11
  6. compiler.threads=posix
  7. compiler.exception=sjlj
  8. arch=x86_64
  9. build_type=Release
  10. [buildenv]
  11. PATH+=(path)C:/path/to/mingw/bin
  12. # other environment we might need like
  13. CXX=C:/path/to/mingw/bin/g++
  14. # etc
  15. [conf]
  16. # some configuration like 'tools.build:compiler_executables' might be needed for some cases

But we can also use a Conan package that contains a copy of the MinGW compiler and use it as a tool_requires instead:

mingw-profile.txt

  1. [settings]
  2. os=Windows
  3. compiler=gcc
  4. compiler.version=12
  5. compiler.libcxx=libstdc++11
  6. compiler.threads=posix
  7. compiler.exception=seh
  8. arch=x86_64
  9. build_type=Release
  10. [tool_requires]
  11. mingw-builds/12.2.0

With this profile we can for example create a package in Windows with:

  1. # Using a basic template project
  2. $ conan new cmake_lib -d name=mypkg -d version=0.1
  3. $ conan create . -pr=mingw
  4. ...
  5. -- The CXX compiler identification is GNU 12.2.0
  6. ...
  7. ======== Testing the package: Executing test ========
  8. mypkg/0.1 (test package): Running test()
  9. mypkg/0.1 (test package): RUN: .\example
  10. mypkg/0.1: Hello World Release!
  11. mypkg/0.1: _M_X64 defined
  12. mypkg/0.1: __x86_64__ defined
  13. mypkg/0.1: _GLIBCXX_USE_CXX11_ABI 1
  14. mypkg/0.1: MSVC runtime: MultiThreadedDLL
  15. mypkg/0.1: __cplusplus201703
  16. mypkg/0.1: __GNUC__12
  17. mypkg/0.1: __GNUC_MINOR__2
  18. mypkg/0.1: __MINGW32__1
  19. mypkg/0.1: __MINGW64__1
  20. mypkg/0.1 test_package

See also