7

我正在尝试使用clVisual Studio 2010 构建 32 位版本的Mixxx。Mixxx 使用 SCons 来构建。我的电脑是 Windows 7 64 位,安装了太多版本的 Visual Studio。

按照这些说明,我尝试了各种组合和变体setenvvsvars但无论我做什么,在这种情况下,我最终都会使用命令行:

> cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

好的,所以cl指向“版本 16,x86”——太好了。

> scons toolchain=msvs force32=1 winlib=%cd%\winlib\x86 sqlitedll=0 staticlibs=1 asmlib=0

[... bunch of output truncated, until we start using the compiler ...]

cl /Fores\qrc_mixxx.obj /c res\qrc_mixxx.cc /TP /Zc:wchar_t- /GL /MP /fp:fast /G
[truncated]
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

(注意——我破解了 SCons 以删除/nologo)什么?现在如何cl表示“版本 18,x64”?它改变了我的环境吗?让我们来了解一下:

Terminate batch job (Y/N)? y

>cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

所以cl对终端来说仍然意味着“版本 16,x86”。但 SCons 总是使用“最新版本,x64”。

(根据我对Windows shell的理解,这应该是不可能的。我杀了脚本,所以它没有做任何清理。cl改变的意思怎么会这样?)

我发现了一些提示:

基于此,我添加了

Environment(MSVC_VERSION = '10.0')
Environment(TARGET_ARCH = 'x86')
print 'hello world'

到 SConstruct。我不知道 SCons,而且构建脚本很重要,所以很可能我做错了。无论如何,SCons 仍然总是使用“最新版本,x64”。

4

3 回答 3

6

您发布的 Environment kwargs 为我工作(Scons 2.3.4):

env = Environment(
    MSVC_VERSION='12.0',
    TARGET_ARCH='x86')

env.Program('src.cpp')

64 位程序的值应TARGET_ARCH='x86_64'根据http://scons.1086193.n5.nabble.com/32-and-64-bit-builds-on-MSVC-td25425.html。的其他值MSVC_VERSION也有效。

于 2014-10-27T16:47:55.463 回答
2

我根据 dirkbaechle 的评论 ( set SCONS_MSCOMMON_DEBUG=-) 打开了日志记录。这很有帮助。当我添加Environment(MSVC_VERSION='10.0')到 SConstruct 时,我可以在输出中看到

get_default_version(): msvc_version:10.0 msvs_version:None
msvc_setup_env: using specified MSVC version '10.0'

[ ... truncated ... ]

get_default_version()
get_default_version(): msvc_version:None msvs_version:None
installed_vcs:['12.0', '10.0', '10.0Exp', '9.0']
msvc_setup_env: using default installed MSVC version '12.0'

糟糕——当我们get_default_version第二次调用时,似乎我们正在使用不同的环境。我不太了解 Mixxx 构建脚本,不知道为什么,但我很确定这就是原因。

简单的解决方法

对于像我这样懒得修复他们的构建脚本的人来说,有一种简单(但丑陋)的方法可以迫使 SCons 做你想做的事。你只需要故意破坏你的新版本(当然是暂时的)。比如我想用2010,x86。首先,我重命名了所有更高版本的“VC”目录。

  • C:\Program Files (x86)\Microsoft Visual Studio 12.0\ VC重命名为_DISABLED_VC
  • C:\Program Files (x86)\Microsoft Visual Studio 11.0\ VC重命名为_DISABLED_VC

现在 SCons 将使用 2010(又名“Microsoft Visual Studio 10.0”),因为所有更高版本都不可用。选择目标架构是类似的。

  • C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\ amd64重命名为_DISABLED_amd64
  • 对ia64x86_amd64x86_ia64等执行相同的操作。
于 2014-07-18T03:41:49.490 回答
-1

我尝试使用 env = Environment(blabla) 设置 TARGET_ARCH,但没有帮助

所以我在 Scons 目录 (...\PythonDir\scons-3.0.1\Scons) 中搜索了“TARGET_ARCH”。在我的情况下,它位于Environment.py文件中,该文件有一个带有默认值的部分。我将更改为“x86”

# Now set defaults for TARGET_{OS|ARCH}
...
# self._dict['TARGET_ARCH']    = self._dict.get('TARGET_ARCH',None)
self._dict['TARGET_ARCH']    = self._dict.get('TARGET_ARCH','x86')

然后我删除了之前编译的Environment.pyc,导致它被重新生成

它奏效了!

于 2018-07-19T00:25:07.317 回答