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?
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'])
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With