我目前正在设置 SCons 以与作为主机操作系统的 Windows 进行交叉编译。我正在构建自定义 Environment对于交叉编译器,但 SCons 每次启动时都坚持寻找 Visual Studio(并打印一条警告说它找不到它,因为我没有安装它)。我可以阻止它寻找我知道我不会使用的标准工具吗?

请您参考如下方法:

至少有两种方法可以做到,第一种方法最简单,尝试创建指定编译器的环境,如下:

env = Environment(CC = '/path/to/the/compiler') 

您可能还需要为链接器和其他工具添加路径。然后 SCons 不应该搜索它们。

另一种方法是使用 tools 为交叉编译器创建一个工具定义。关于 Environment() 的争论 中提到的功能配置文件引用 SCons man page的部分,其中提到以下内容:

Additionally, a specific set of tools with which to initialize the environment may be specified as an optional keyword argument:

env = Environment(tools = ['msvc', 'lex'])

Non-built-in tools may be specified using the toolpath argument:

env = Environment(tools = ['default', 'foo'], toolpath = ['tools'])

...

The individual elements of the tools list may also themselves be two-element lists of the form (toolname, kw_dict). SCons searches for the toolname specification file as described above, and passes kw_dict, which must be a dictionary, as keyword arguments to the tool's generate function. The generate function can use the arguments to modify the tool's behavior by setting up the environment in different ways or otherwise changing its initialization.



工具/my_tool.py:

def generate(env, **kw): 
  # Sets MY_TOOL to the value of keyword argument 'arg1' or 1. 
  env['MY_TOOL'] = kw.get('arg1', '1') 
def exists(env): 
  return 1 

S构造:

env = Environment(tools = ['default', ('my_tool', {'arg1': 'abc'})], 
                  toolpath=['tools']) 


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!