我有这个SConstruct文件:
env=Environment()
env.Append(CCFLAGS = ['-std=c99', '-Wall', '-Wextra', '-g'])
print env["CCFLAGS"]
#Program('test_array.c',CCFLAGS=['-std=c99', '-Wall', '-Wextra', '-g'],
CPPPATH = '.', LIBS='stuff', LIBPATH=".")
#Program('test_array.c',CPPPATH = '.', LIBS='stuff', LIBPATH=".")
取消注释第一个Program()的输出是:
scons
scons: Reading SConscript files ...
-std=c99 -Wall -Wextra -g
scons: done reading SConscript files.
scons: Building targets ...
gcc -o test_array.o -c -std=c99 -Wall -Wextra -g -I. test_array.c
gcc -o test_array test_array.o -L. -lstuff
scons: done building targets.
取消注释第二个Program()的输出是:
scons
scons: Reading SConscript files ...
-std=c99 -Wall -Wextra -g
scons: done reading SConscript files.
scons: Building targets ...
gcc -o test_array.o -c -I. test_array.c
test_array.c: In function 'test_insert':
test_array.c:85:4: error: 'for' loop initial declarations are only allowed in C99 mode
test_array.c:85:4: note: use option -std=c99 or -std=gnu99 to compile your code
env变量有一个CCFLAGS值,但我不知道为什么它没有在Program()调用中没有明确指定时使用。
答案 0 :(得分:3)
Program()构建器从DefaultEnvironment()获取构造变量,而不是从您创建的env中获取。此行为的描述为here。
尝试以下方法:
env=Environment()
env.Append(CCFLAGS = ['-std=c99', '-Wall', '-Wextra', '-g'])
print env["CCFLAGS"]
# Program() will take the construction vars from env, not the DefaultEnvironment()
#env.Program('test_array.c',CCFLAGS=['-std=c99', '-Wall', '-Wextra', '-g'],
CPPPATH = '.', LIBS='stuff', LIBPATH=".")
#env.Program('test_array.c',CPPPATH = '.', LIBS='stuff', LIBPATH=".")
注意我在您创建和修改的env
上调用Program()构建器。
所以,你真正需要的是第二个电话,如下:
env=Environment()
env.Append(CCFLAGS = ['-std=c99', '-Wall', '-Wextra', '-g'])
print env["CCFLAGS"]
# Program() will take the construction vars from env, not the DefaultEnvironment()
env.Program('test_array.c',CPPPATH = '.', LIBS='stuff', LIBPATH=".")