Use scons instead of makefile to quickly build applications

Source: Internet
Author: User

Use scons instead of makefile to quickly build applications
  • Author: Liu Da-poechant
  • Blog: blog.csdn.net/poechant
  • Email: zhongchao.ustc@gmail.com
  • Copyright · poechant
0 Introduction

Writing building rules for make tools is not easy. Its Complex Configuration Rules are daunting for experienced developers. Many alternatives to the Make tool were born. scons is one of them. Scons is a program written in Python similar to the Make tool. Compared with the make tool, the scons configuration file is simpler and clearer. In addition, it has many advantages.

Scons supports a variety of operating system platforms to achieve program building portability.

1 install
$ tar -xvf scons-2.0.1.tar$ cd scons-2.0.1 $ sudo python setup.py install
2 Hello world2.1 source file
#include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) {    printf("Hello, SCons!\n");     return 0; }
2.2 Config File
Program('helloscons.c')
2.3 build
$ ls helloscons helloscons.c  SConstruct$ cd helloscons/ $ scons scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... gcc -o helloscons.o -c helloscons.c gcc -o helloscons helloscons.o scons: done building targets. $ ls helloscons  helloscons.c  helloscons.o  SConstruct$ ./helloscons Hello, SCons!
2.4 run
$ ./helloscons Hello, SCons!
2.5 clean
$ scons -c scons: Reading SConscript files ... scons: done reading SConscript files. scons: Cleaning targets ... Removed helloscons.o Removed helloscons scons: done cleaning targets.$ ls -ahelloscons.c  SConstruct .sconsign.dblite
3 improve your skills! 3.1 specify your Executable File Name
Program('myscons, 'helloscons.c')
3.2 be quiet when building!
$ scons -Q 
3.3 a little more complicated program
Program('helloscons2', ['helloscons2.c', 'file1.c', 'file2.c'],     LIBS = 'm',     LIBPATH = ['/usr/lib', '/usr/local/lib'],     CCFLAGS = '-DHELLOSCONS')$ scons -Q gcc -o file1.o -c -DHELLOSCONS file1.c gcc -o file2.o -c -DHELLOSCONS file2.c gcc -o helloscons2.o -c -DHELLOSCONS helloscons2.c gcc -o helloscons2 helloscons2.o file1.o file2.o -L/usr/lib -L/usr/local/lib -lm 
3.4 Regular Expression
Program('helloscons2', Glob('*.c') 
4 reference
  1. Http://www.ibm.com/developerworks/cn/linux/l-cn-scons/index.html? CA = Drs-

-

For more information, see "LIU Da's csdn blog": blog.csdn.net/poechant

-

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.