Install scons ====
This is not detailed. If it is too troublesome, you can directly use sudo apt-Get install scons. Do not bother to download the source code for installation.
Simple compilation ====
Let's look at the simplest Hello, world program.
Int
Main ()
{
Printf ("Hello, world! \ N ");
}
Create a sconstruct file and write
Program ('hello. C ')
The simplest automated compilation file contains two pieces of information. First, it indicates that the result to be compiled is an executable file, and second, it indicates that the input file is
Hello. C.
In this case, you can run scons on the command line terminal to automatically compile the code.
% Scons
Scons: Reading sconscript files...
Scons: done reading sconscript files.
Scons: building targets...
CC-O hello. O-C hello. c
CC-O hello. o
Scons: done building targets.
Scons only needs to know the name of the input file to automatically export the dependent file and find the compiler automatically. Here is GCC.
Building object files ====
In addition to specifying the output file as an executable file, you can also specify the output file as a. o file.
Object ('hello. C ')
Output
% Scons
Scons: Reading sconscript files...
Scons: done reading sconscript files.
Scons: building targets...
CC-O hello. O-C hello. c
Scons: done building targets.
Cleanup ====
After compiling the output executable file, the remaining. O files are redundant. You can add option-C to execute cleanup.
% Scons
Scons: Reading sconscript files...
Scons: done reading sconscript files.
Scons: building targets...
CC-O hello. O-C hello. c
CC-O hello. o
Scons: done building targets.
% Scons-C
Scons: Reading sconscript files...
Scons: done reading sconscript files.
Scons: cleaning targets...
Removed hello. o
Removed hello
Scons: done cleaning targets.
Sconstruct file ====
Similar to the Make tool, scons organizes and compiles Based on the sconstruct file. However, sconstruct uses the python syntax, which is much better than makefile.
If you think that scons outputs too much information during compilation and is dazzled, add a-q so that the entries starting with scons are hidden and not displayed.
C: \> scons-Q
CL/fohello. OBJ/C hello. c/nologo
Link/nologo/out: hello.exe hello. OBJ
Embedmanifestexecheck (target, source, ENV)
Ilding object files