简体   繁体   English

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

[英]C++ Build Environment using MinGW-w64 and Boost.Build

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. 我目前正在将我的一个项目移植到GCC,我正在使用MinGW-w64项目完成此任务,因为我需要x64和x86支持。

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). 我的项目目前使用Boost C ++库,为了简化构建过程,我在项目中也使用了Boost.Build(因为它使集成变得简单)。

Under MSVC this is fine, because I can do the following from the command line: 在MSVC下这很好,因为我可以从命令行执行以下操作:

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. 由于32位和64位工具链位于不同的目录中,MinGW-w64使这个“有问题”。 (C:\\MinGW32 and C:\\MinGW64 respectively). (分别为C:\\ MinGW32和C:\\ MinGW64)。

Is it possible to set up Boost.Build in a way that it will choose the correct toolchain based on the address-model flag? 是否可以设置Boost.Build,它将根据地址模型标志选择正确的工具链? 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). 如果它有帮助,我在MinGW-w64网站的“Personal Builds”文件夹中使用rubenvb 4.6.3-1版本(我特别使用这些版本,因为我希望尝试让我的代码解析 - 但不能编译 - 在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. 我刚才想到的一个解决方案是在编译之前“手动”将PATH设置为指向正确的工具链,但是这会给我的构建过程增加一层额外的复杂性,我想避免。 Ideally I would like it to be as easy as it is for MSVC, though I understand this may not be possible. 理想情况下,我希望它像MSVC一样简单,但我知道这可能是不可能的。 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. 在最坏的情况下,我假设我刚刚建议的工作,我只需要在调用Boost.Build之前添加脚本来正确设置PATH。 That would mean hardcoding a path though, which I don't want to do... 这意味着硬编码路径,我不想做...

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). 通过添加工具集要求(使用toolset.add-requirements规则),Yo可以根据一组匹配属性选择任何Boost.Build工具集。 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. 在某些工具darwin.jam有内置支持,例如darwin.jam (Xcode),但遗憾的是我们还没有将它添加到gcc工具darwin.jam But you can use the same minimal code in your user-config.jam when declaring the toolsets. 但是,在声明工具集时,您可以在user-config.jam使用相同的最小代码。 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. ..Forgot提到..即使这是创建两个不同的工具集声明,默认仍然是动态选择。 One would use the usual command line: 一个人会使用通常的命令行:

b2 toolset=gcc address-model=64

To use the 64 bit mingw compiler. 使用64位mingw编译器。

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). 由于MinGW二进制文件具有不同的名称,因此您应该能够将booth目录包含在路径中,然后在jam配置文件中添加两个不同的工具集,您可以在其中指定二进制文件的确切名称(不包括路径)。

In the config file add the following based on the format 在配置文件中,根据格式添加以下内容

using gcc : [version] : [c++-compile-command] : [compiler options] ; 使用gcc:[version]:[c ++ - compile-command]:[编译器选项];

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:

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

MinGW-w64 can build 32 and 64 bits binaries. MinGW-w64可以构建32位和64位二进制文​​件。

I use tdm-mingw with mingw64 toolchan and only pass -m32 or -m64 to linker / compiler to select version. 我使用mdw-mingw和mingw64 toolchan,只将-m32-m64传递给链接器/编译器以选择版本。 In default 64 bits binaries are build. 默认情况下,64位二进制文​​件是构建的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM