编译
重定义目标输出文件名称
admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day3
$ scons
scons: Reading SConscript files ...
Finished calling Program()
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o hello.exe hello.o
gcc -o new_hello.exe hello.o
scons: done building targets.
admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day3
$ ls
SConstruct hello.c hello.exe hello.o new_hello.exe
可以看到有两个文件输出,分别是默认输出文件 hello.exe
和 new_hello.exe
。
编译多文件
在实际工程中,不会只编译一个文件,这样就无法体现出来 scons
的作用了。一般情况下,是对整个工程内的多个文件共同编译,同时也可能涉及到多个文件夹。和开发者创建的工程目录有关系。
编译同一个文件夹下的多个源文件
admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day3
$ scons
scons: Reading SConscript files ...
Finished calling Program()
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o src_file1.o -c src_file1.c
gcc -o src_file2.o -c src_file2.c
gcc -o hello.exe hello.o src_file1.o src_file2.o
scons: done building targets.
admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day3
$ ls
SConstruct hello.exe src_file1.c src_file2.c ????.md
hello.c hello.o src_file1.o src_file2.o
admin@DESKTOP-NQU1HUV C:\Users\admin\Desktop\scons\day3
$ hello.exe
hello
file1
file2
在生成的文件中,可以看到每个源文件都对应一个目标文件(.o),同时可以看到生成了一个 hello.exe
文件,运行该文件,可以看到分别输出三条语句。
下面我们修改一下 SConstruct
文件内容,看一下生成的文件是否有不同。
# Program(['hello.c',