SCons User Guide 0.93 | ||
---|---|---|
<<< Previous | Simple Builds | Next >>> |
You've just seen how to configure SCons to compile a program from a single source file. It's more common, of course, that you'll need to build a program from many input source files, not just one. To do this, you need to put the source files in a Python list (enclosed in square brackets), like so:
Program(['prog.c', 'file1.c', 'file2.c']) |
A build of the above example would look like:
% scons -Q
cc -c -o file1.o file1.c
cc -c -o file2.o file2.c
cc -c -o prog.o prog.c
cc -o prog prog.o file1.o file2.o
Notice that SCons deduces the output program name from the first source file specified in the list--that is, because the first source file was prog.c, SCons will name the resulting program prog (or prog.exe on a Windows system). If you want to specify a different program name, then you slide the list of source files over to the right to make room for the output program file name. (SCons puts the output file name to the left of the source file names so that the order mimics that of an assignment statement: "program = source files".) This makes our example:
Program('program', ['main.c', 'file1.c', 'file2.c']) |
On Linux, a build of this example would look like:
% scons -Q
cc -c -o file1.o file1.c
cc -c -o file2.o file2.c
cc -c -o main.o main.c
cc -o program main.o file1.o file2.o
Or on Windows:
C:\>scons -Q
cl /nologo /c file1.c /Fofile1.obj
cl /nologo /c file2.c /Fofile2.obj
cl /nologo /c main.c /Fomain.obj
link /nologo /OUT:program.exe main.obj file1.obj file2.obj
<<< Previous | Home | Next >>> |
Making the Output Less Verbose | Up | Keeping SConstruct Files Easy to Read |