【问题标题】:How do I cross-compile scons (with gcc) on Windows with Visual Studio installed?如何在安装了 Visual Studio 的 Windows 上交叉编译 scons(使用 gcc)?
【发布时间】:2019-06-24 10:29:42
【问题描述】:

我有一个现有的 makefile 项目,我正在迁移到 scons

makefile 使用 gccg++ 构建多个 Windows 可执行文件。

不过,我还安装了用于 C# 开发的 Visual Studio。

scons 似乎正在尝试使用 Visual Studio 工具而不是 gcc 工具:

cl /Fofoo\bar.o /c foo\bar.c /nologo -g -mno-ms-bitfields -fshort-enums -ftest-coverage -fprofile-arcs /D-DUNIT_TESTS /I. <more includes follow...>
cl : Command line warning D9002 : ignoring unknown option '-g'

我已经阅读了几个答案并尝试添加:

env["CC"] = "gcc"
env["CXX"] = "g++"
env["LINK"] = "g++"

在我的Sconstruct 文件中。这具有正确更改工具的效果,但不是命令语法:

gcc /Fofoo\bar.o /c foo\bar.c /nologo -g -mno-ms-bitfields -fshort-enums -ftest-coverage -fprofile-arcs /D-DUNIT_TESTS /I. <more includes follow...>
gcc: error: /Fofoo\bar.o: No such file or directory

我如何确保 scons 使用我想要的工具,并使用正确的命令行选项语法(例如 -I 而不是 /I)?

【问题讨论】:

标签: gcc g++ scons


【解决方案1】:

如果我不得不猜测你的 SConstruct 的问题是这样的:

env=Environment()
env["CC"] = "gcc"
env["CXX"] = "g++"
env["LINK"] = "g++"
env['CCFLAGS']='-mno-ms-bitfields -fshort-enums -ftest-coverage -fprofile-arcs'
env['CPPDEFINES']=['-DUNIT_TESTS']
env['CPPPATH'] = ['.']

鉴于要在 Windows 上配置的默认工具列表按顺序如下,一旦找到其中之一,它将停止配置工具,然后设置适用于此类工具的标志。

c_compilers = ['msvc', 'mingw', 'gcc', 'intelc', 'icl', 'icc', 'cc', 'bcc32']

您需要明确列出您想要初始化的工具(并且不允许 SCons 添加默认工具)以及它们所在的 PATH。此外,您的 CPPDEFINES 应该是 ['UNIT_TESTS'] 而不是 ['- DUNIT_TESTS'] SCons 将添加适当的标志。请注意,如果您在构建中使用它们,您可能需要添加其他工具。

env=Environment(tools=[])
env.AppendENVPath('PATH', PATH_TO_YOUR_COMPILERS)
for tool in ['gcc','gnulink','ar']:
   env.Tool(tool)
env['CCFLAGS']='-mno-ms-bitfields -fshort-enums -ftest-coverage -fprofile-arcs'
env['CPPDEFINES']=['UNIT_TESTS']
env['CPPPATH'] = ['.']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多