【SCons 002】Win10 SCon环境搭建

1. 熟悉文档

大概看了下前面下载的几篇文档,
《scons-user.pdf》 这篇时作为我们小白入门的主要参考文档
《scons-man.pdf》这篇主要是对SCons的一些深入介绍,比如各个命令等
《scons-api.pdf》从字面意思可以看出,这个主要是介绍了SCons的一些现场的package api
《scons-design.pdf》这篇我大概翻了翻,看起来听高端,记录了SCons整个设计过程的一些思想

好,确定文档,我们将主要围绕 《scons-user.pdf》这篇文档先入门。
大概看了下整个目录,规划的挺不错,从第一章安装开始从浅入深,到后面的自动编译等,挺适合我这种小白,哈哈,废话不多说!开始吧

2. 安装环境(Win10基础上学习)

①首先安装Python

C:\Users\Administrator>python -V
Python 3.7.2

②安装SCons
在文档中讲述了各个情况下的安装步骤及安装命令,此处我们使用第一种最简单的方法
命令: python -m pip install scons

在cmd中敲入上述命令,结果如下:
C:\Users\Administrator>python -m pip install scons
Collecting scons
  Downloading https://files.pythonhosted.org/packages/13/31/43b96f5b79731468a6731e4dbc71601f67fdeddad053bd4f1d1e2f0dbeec/scons-3.0.4-py2.py3-none-any.whl (829kB)
    100% |████████████████████████████████| 839kB 29kB/s
Installing collected packages: scons
Successfully installed scons-3.0.4

Scons安装成功后,参考《scons-man.pdf》,可以使用scons -v 查看当前的版本好,

C:\Users\Administrator>scons -v
SCons by Steven Knight et al.:
        script: v3.0.4.3a41ed6b288cee8d085373ad7fa02894e1903864, 2019-01-20 22:51:36, by bdeegan on kufra
        engine: v3.0.4.3a41ed6b288cee8d085373ad7fa02894e1903864, 2019-01-20 22:51:36, by bdeegan on kufra
        engine path: ['c:\\program files\\python\\python37\\lib\\site-packages\\scons\\SCons']
Copyright (c) 2001 - 2019 The SCons Foundation

### 使用 -h 或者 --help 可以查看scons的使用方法
C:\Users\Administrator>scons -h
usage: scons [OPTION] [TARGET] ...

SCons Options:
  -b, -d, -e, -m, -S, -t, -w, --environment-overrides, --no-keep-going,
  --no-print-directory, --print-directory, --stop, --touch
                              Ignored for compatibility.
  -c, --clean, --remove       Remove specified targets and dependencies.
  -C DIR, --directory=DIR     Change to DIR before doing anything.
  --cache-debug=FILE          Print CacheDir debug info to FILE.
  --cache-disable, --no-cache

3. 简单的小程序

我在桌面上新建一个目录,scons_study 用来暂时保存scons学习的一些用例(后续会删除)

在目录中,简单的编写一个hello world的C程序 和 一个名为SConstruct的文件,如下:

//hello.c
int main()
{
 printf("Hello, world!\n");
}

//SConstruct
Program('hello.c')

在命令行中进入 scons_study 目录,执行scons
执行后,发现报如下错误,那是因为我的win10电脑没有安装C/C++编译器

C:\Users\Administrator\Desktop\scons_study>scons
scons: Reading SConscript files ...

scons: warning: No version of Visual Studio compiler found - C/C++ compilers most likely not set correctly
File "C:\Users\Administrator\Desktop\scons_study\SConstruct", line 1, in <module>
scons: done reading SConscript files.
scons: Building targets ...
cl /Fohello.obj /c hello.c /nologo
'cl' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
scons: *** [hello.obj] Error 1
scons: building terminated because of errors.

C:\Users\Administrator\Desktop\scons_study>

如果您也遇到和我一样的没有c编译器的情况,
此处请跳转到本文 第四章 4. Win10 上安装 Visual Studio C++

①编译C语言
安装完毕后, 在命令行中敲scons会开始编译,编译完毕后生成hello.exe,可以在命令行中执行hello.exe,结果如下:
在这里插入图片描述
同样,文档中说的编译 Java 也是一个道理,但因为我电脑没有安装JAVA环境,并且我们的重点是学会SCons语法,所以此处就不做实验.

②清理编译生成的文件 scons -c

## 使用scons编译生成 hello.obj 和 hello.exe 两个文件
PS C:\Users\Administrator\Desktop\scons_study\001> scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /Fohello.obj /c hello.c /nologo
hello.c
link /nologo /OUT:hello.exe hello.obj
scons: done building targets.

## 使用scons -c 会将编译生成的 hello.obj 和 hello.exe 两个文件 删除
PS C:\Users\Administrator\Desktop\scons_study\001> scons -c
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed hello.obj
Removed hello.exe
scons: done cleaning targets.
PS C:\Users\Administrator\Desktop\scons_study\001>

4. Win10 上安装 Visual Studio C++

接下来,我们开始下载一个Visual Studio C++
我随便找了一个Visual Studio 2017 ,要求不高,能用就行
https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=Community&rel=15

在这里插入图片描述
下载好后,双击运行,开始正式下载安装包
在这里插入图片描述
下载好后,可以选择自己想要的功能,此处,我选择了
使用C++的桌面开发
在这里插入图片描述
接下来正式下载 Visual Studio
在这里插入图片描述
下载完毕后,注意需要重启电脑
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

"小夜猫&小懒虫&小财迷"的男人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值