C/C++ 构建器识别一组特定的参数,称为Construction Variables。
这些变量可以在环境中设置,也可以在调用构建器时设置,就像您在问题中所做的那样。在环境中设置它们通常更容易,从而使对构建器的调用更简单,然后只在必要时修改变量。
这是一个例子:
env = Environment()
# Notice that CPPPATH, CPPDEFINES, LIBS, and LIBPATH dont include the
# compiler flags -I, -D, -l, and -L respectively, SCons will add those
# in a platform independent manner
env.Append(CCFLAGS=['-g', '-O2'])
env.Append(CPPPATH=['some/include/path'])
env.Append(CPPDEFINES=['YOUR_DEFINE'])
env.Append(LIBS=['pthread'])
env.Append(LIBPATH=['some/lib/path'])
# All of these builder calls use the construction
# variables set on the environment above
env.Object('hello.c')
env.Object('goodbye.c')
env.Program('main.cc')
如果要覆盖特定变量,可以执行以下操作
env.Object('hello.c', CPPDEFINES='HELLO')
或者,如果您想附加到特定变量,只需一次调用,您可以执行以下操作:
env.Object('hello.c', CPPDEFINES=[env['CPPDEFINES'], 'HELLO'])