问题
I am currently setting up SCons for cross-compilation with Windows as the host OS. I am building a custom Environment
for the cross-compiler, but SCons insists on looking for Visual Studio each time I start it up (and prints a warning that it cannot find it, because I don't have it installed). Can I prevent it from looking for standard tools I know I am not going to use?
回答1:
There are at least 2 ways to do this, the first way is the easiest, try creating the environment specifying the compiler, as follows:
env = Environment(CC = '/path/to/the/compiler')
You'll probably need to add paths for the linker and other tools as well. Then SCons shouldnt search for them.
Another way to do it would be to create a tool definition for the cross-compiler using the tools
argument on the Environment()
function as mentioned in the CONFIGURATION FILE REFERENCE section of the SCons man page, where the following is mentioned:
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.
tools/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
SConstruct:
env = Environment(tools = ['default', ('my_tool', {'arg1': 'abc'})],
toolpath=['tools'])
回答2:
You may suppress warnings like this
env.SetOption('warn', 'no-visual-c-missing')
For example, to cross-compile for ARM Cortex-M microcontrollers I'm doing this
cross = 'arm-none-eabi-'
toolchain = {
'CC': cross + 'gcc',
'CXX': cross + 'g++',
'AR': cross + 'ar',
'AS': cross + 'gcc',
'OBJCOPY': cross + 'objcopy',
'SIZE': cross + 'size',
'PROGSUFFIX': '.elf',
}
env = Environment(tools=('gcc', 'g++', 'gnulink', 'ar', 'as'), ENV=os.environ)
env.SetOption('warn', 'no-visual-c-missing')
env.Replace(**toolchain)
回答3:
Consider redefining the DefaultEnvironment instead of defining an Environment
.
All of the Builder functions that we've introduced so far, like Program and Library, actually use a default construction environment that contains settings for the various compilers and other tools that SCons configures by default, or otherwise knows about and has discovered on your system. The goal of the default construction environment is to make many configurations to "just work" to build software using readily available tools with a minimum of configuration changes.
This way, SCons won't try to make predictions based on common usage and apply them to your project. For example:
PATH = {'PATH' : ['C:/cygwin/bin']}
env = Environment(ENV=PATH)
env.Program('helloworld.c++')
will make assumptions based on what it thinks is the most likely case & try to find Visual Studio before resorting to whatever it finds in PATH, whereas:
PATH = {'PATH' : ['C:/cygwin/bin']}
env = DefaultEnvironment(ENV=PATH)
env.Program('helloworld.c++')
will make no such a assumption, and go directly to whatever it finds in PATH without looking for Visual Studio.
来源:https://stackoverflow.com/questions/15205210/prevent-scons-from-looking-for-standard-tools