Reputation: 7059
I have this SConstruct file:
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=".")
The output from uncommenting the first Program() is:
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.
The output from uncommenting the second Program() is:
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
The env variable has a value for CCFLAGS but I don't know why it isn't being used when not explicitly specified in the Program() call.
Upvotes: 2
Views: 1658
Reputation: 10357
The Program() builder is taking the construction variables from the DefaultEnvironment(), not from the env you created. This behavior is described here.
Try the following:
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=".")
Notice I call the Program() builder on the env
you created and modified.
So, all you really need is the second call, as follows:
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=".")
Upvotes: 3