C++使用 MinGW-w64 和 Boost.Build 构建环境

发布于 2024-12-25 12:01:39 字数 827 浏览 1 评论 0原文

我目前正在将我的一个项目移植到 GCC,并且我正在使用 MinGW-w64 项目来完成此任务,因为我需要 x64 和 x86 支持。

不过,我在设置构建环境时遇到了问题。我的项目当前使用 Boost C++ 库,为了使构建过程更容易,我也在我的项目中使用 Boost.Build(因为它使集成变得简单)。

在 MSVC 下这很好,因为我可以从命令行执行以下操作:

b2 toolset=msvc address-model=32 # compile as 32-bit
b2 toolset=msvc address-model=64 # compile as 64-bit

MinGW-w64 使这个问题变得“有问题”,因为 32 位和 64 位工具链位于不同的目录中。 (分别为 C:\MinGW32 和 C:\MinGW64)。

是否可以设置 Boost.Build,使其根据地址模型标志选择正确的工具链?如果没有,我的下一个最佳选择是什么?

编辑:

如果有帮助,我正在使用“个人构建”文件夹中 MinGW-w64 网站的 rubenvb 4.6.3-1 构建(我特别使用这些构建,因为我希望尝试解析我的代码 - 但是无法编译 - 在 Clang 下)。

编辑:

我刚刚想到的一个解决方案是在编译之前“手动”设置 PATH 以指向正确的工具链,但是这给我的构建过程增加了一层额外的复杂性,我想避免这种情况。理想情况下,我希望它像 MSVC 一样简单,尽管我知道这可能不可能。在最坏的情况下,我假设我刚才建议的方法会起作用,并且我只需要在调用 Boost.Build 之前添加脚本来正确设置 PATH。这意味着对路径进行硬编码,但我不想这样做......

I'm currently porting one of my projects to GCC, and I'm using the MinGW-w64 project to accomplish this as I require both x64 and x86 support.

I've hit a problem in setting up my build environment though. My project currently uses the Boost C++ libraries, and to make the build process easier I use Boost.Build in my project too (as it makes integration simple).

Under MSVC this is fine, because I can do the following from the command line:

b2 toolset=msvc address-model=32 # compile as 32-bit
b2 toolset=msvc address-model=64 # compile as 64-bit

MinGW-w64 is making this 'problematic', as the 32-bit and 64-bit toolchains are housed in separate directories. (C:\MinGW32 and C:\MinGW64 respectively).

Is it possible to set up Boost.Build in a way that it will choose the correct toolchain based on the address-model flag? If not, what is my next best option?

EDIT:

If it helps, I am using the rubenvb 4.6.3-1 builds from the MinGW-w64 website in the "Personal Builds" folder (I am using these builds in particular as I wish to try getting my code to parse - but not compile - under Clang).

EDIT:

One solution I just thought of would be to 'manually' set the PATH to point to the correct toolchain before compilation, however this adds an extra layer of complication to my build process which I'd like to avoid. Ideally I would like it to be as easy as it is for MSVC, though I understand this may not be possible. In the worst case I assume what I just suggested would work, and I would just have to add scripts to correctly set the PATH before invoking Boost.Build. That would mean hardcoding a path though, which I don't want to do...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰雪之触 2025-01-01 12:01:39

您可以通过添加工具集要求(使用 toolset.add-requirements 规则)来根据一组匹配属性选择任何 Boost.Build 工具集。某些工具集中对此有内置支持,例如 darwin.jam (Xcode),但不幸的是我们尚未将其添加到 gcc 工具集中。但是,在声明工具集时,您可以在 user-config.jam 中使用相同的最少代码。对于您的情况,它可能如下所示:

import toolset ;

using gcc : gcc-4.6.3~32 : /path/to/32bit/mingw/gcc ;
using gcc : gcc-4.6.3~64 : /path/to/64bit/mingw/gcc ;

# Add a global target requirements to "choose" the toolset based on the address model.
toolset.add-requirements <toolset>gcc-4.6.3~32:<address-model>32 ;
toolset.add-requirements <toolset>gcc-4.6.3~64:<address-model>64 ;

这具有将给定条件要求添加到所有目标的效果。其作用是根据需要为特定声明的工具集选择特定目标。

..忘记提及..即使这是创建两个不同的工具集声明,默认值仍然是动态选择的。可以使用常用的命令行:

b2 toolset=gcc address-model=64

使用 64 位 mingw 编译器。

Yo can make any Boost.Build toolset be chosen based on a set of matching properties by adding a toolset requirement (with the toolset.add-requirements rule). There is built-in support for this in some toolsets, like darwin.jam (Xcode), but unfortunately we haven't added that to the gcc toolset yet. But you can use the same minimal code in your user-config.jam when declaring the toolsets. For you case it might look like this:

import toolset ;

using gcc : gcc-4.6.3~32 : /path/to/32bit/mingw/gcc ;
using gcc : gcc-4.6.3~64 : /path/to/64bit/mingw/gcc ;

# Add a global target requirements to "choose" the toolset based on the address model.
toolset.add-requirements <toolset>gcc-4.6.3~32:<address-model>32 ;
toolset.add-requirements <toolset>gcc-4.6.3~64:<address-model>64 ;

This has the effect of adding the given conditional requirement to all the targets. Which has the effect of selecting a particular target for a particular declared toolset as needed.

..Forgot to mention.. That even though this is creating two different toolset declarations the default is still chosen dynamically. One would use the usual command line:

b2 toolset=gcc address-model=64

To use the 64 bit mingw compiler.

单身狗的梦 2025-01-01 12:01:39

由于 MinGW 二进制文件具有不同的名称,您应该能够将 Booth 目录包含到路径中,然后在 jam 配置文件中添加两个不同的工具集,在其中指定二进制文件的确切名称(不包括路径)。

在配置文件中根据格式添加以下内容

使用 gcc : [版本] : [c++-compile-command] : [编译器选项] ;

using gcc : 32 : mingw-w32-1.0-bin_i686-mingw ;
using gcc : 64 : mingw-w64-1.0-bin_i686-mingw ;

然后您应该能够像这样调用 b2:

b2 toolset=gcc-32
bt toolset=gcc-64

Since the MinGW binaries have different names you should be able to include booth directories into the path and then add two different toolsets in the jam configuration file, where you specify the exact names of the binary files (excluding the path).

In the config file add the following based on the format

using gcc : [version] : [c++-compile-command] : [compiler options] ;

using gcc : 32 : mingw-w32-1.0-bin_i686-mingw ;
using gcc : 64 : mingw-w64-1.0-bin_i686-mingw ;

You should then be able to call b2 like this:

b2 toolset=gcc-32
bt toolset=gcc-64
凉墨 2025-01-01 12:01:39

MinGW-w64 可以构建 32 和 64 位二进制文​​件。

我将 tdm-mingw 与 mingw64 toolchan 一起使用,并且仅将 -m32-m64 传递给链接器/编译器来选择版本。默认情况下构建 64 位二进制文​​件。

MinGW-w64 can build 32 and 64 bits binaries.

I use tdm-mingw with mingw64 toolchan and only pass -m32 or -m64 to linker / compiler to select version. In default 64 bits binaries are build.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文