在 Windows 中使用 MinGW 作为 tool_requires 用 gcc 构建¶
如果我们在环境中安装了 MinGW,我们可以定义一个类似这样的配置文件:
[settings]
os=Windows
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
compiler.threads=posix
compiler.exception=sjlj
arch=x86_64
build_type=Release
[buildenv]
PATH+=(path)C:/path/to/mingw/bin
# other environment we might need like
CXX=C:/path/to/mingw/bin/g++
# etc
[conf]
# some configuration like 'tools.build:compiler_executables' might be needed for some cases
但我们也可以使用包含 MinGW 编译器副本的 Conan 包,并将其用作 tool_requires
[settings]
os=Windows
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
compiler.threads=posix
compiler.exception=seh
arch=x86_64
build_type=Release
[tool_requires]
mingw-builds/12.2.0
使用此配置文件,我们可以在 Windows 中例如创建如下包:
# Using a basic template project
$ conan new cmake_lib -d name=mypkg -d version=0.1
$ conan create . -pr=mingw
...
-- The CXX compiler identification is GNU 12.2.0
...
======== Testing the package: Executing test ========
mypkg/0.1 (test package): Running test()
mypkg/0.1 (test package): RUN: .\example
mypkg/0.1: Hello World Release!
mypkg/0.1: _M_X64 defined
mypkg/0.1: __x86_64__ defined
mypkg/0.1: _GLIBCXX_USE_CXX11_ABI 1
mypkg/0.1: MSVC runtime: MultiThreadedDLL
mypkg/0.1: __cplusplus201703
mypkg/0.1: __GNUC__12
mypkg/0.1: __GNUC_MINOR__2
mypkg/0.1: __MINGW32__1
mypkg/0.1: __MINGW64__1
mypkg/0.1 test_package
另请参阅
ConanCenter 网页上的 mingw-builds 包
The
conan-center-index
mingw-builds Github 仓库 recipe