SCons教程(1) 构建第一个程序

构建第一个程序

使用scons构建hello程序

hello.c 内容

#include <stdio.h>

int main(void)
{
    printf("hello\r\n");

    return 0;
}

SConstruct

Program('hello.c')

在命令窗口中执行 scons 可以自动构建程序,输出如下:

admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day1
$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o hello.exe hello.o
scons: done building targets

在win10上可以看到在当前目录下,会一个 hello.exe 的文件生成。执行 hello.exe 可以在命令窗口看到打印输出。 并且可以看到中间文件 hello.o 的输出。
linux 上,可能会输出其他的文件,都是可以使用的。下面如没有特殊提起,则环境默认是 win10 。

admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day1
$ ls
SConstruct  hello.c  hello.exe  hello.
admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day1
$ hello.exe
hello

编译目标文件(.o)

修改 SConstruct 内容

Object('hello.c')

在命令窗口执行 scons,可以看出只生成了目标文件 hello.o,没有 hello.exe 说明指令起作用了。

admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day1
$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
scons: done building targets.

admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day1
$ ls
SConstruct  hello.c  hello.o

清除构建后的文件

执行 scons -c 可以将构建过程的中间文件清除。

admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day1
$ scons -c
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed hello.o
scons: done cleaning targets.

admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day1
$ ls
SConstruct  hello.c
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值