[Scons translation scons learning] 1. Simple Compilation

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.