基于Windows10基于Linux的C语言笔记Ⅰ

2023-05-16

这玩意儿就是自己的学习笔记,不过,也可以用来入门学习C语言。However,你需要:
学习C语言兴致,
Windows10(或者你有一台Linux系统的电脑),
会用vim/vi、nano或者(其实会用CSDN或Baidu也能解决问题哒~),
end ~


设置系统环境

  • WSL 1
    • What is WSL???
    • Let's turn on (install) it !
  • Linux
  • It's time for C ~

WSL 1

What is WSL???

我有一个 Windows 10,不过我觉得Linux才是最好的系统,所以我需要安装一个Linux虚拟机来作为编程环境。
当然,如果你 只会 坚持用Windows上的IDE或者你是用记事本的大佬,请直接跳过以下所有内容,并且可以选择开始C语言的学习。
同时,这是一个夹带很多私货的笔记 ,大佬轻喷


THEREFORE,虚拟机,启动!

说到虚拟机,有Virtual Box,Vmware,balabala有好多,但都是挺大的一个家伙,虚拟机内外切换使用也不方便。。。那么:算了吧

谢谢大家,这篇blog到此结束

额,还想接着看?
好吧,那让我们看看 Macrohard 偷偷藏在Win10里的WSL吧~

What is WSL?
The Windows Subsystem for Linux lets developers run a GNU/Linux environment – including most command-line tools, utilities, and applications – directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.

说人话就是:Windows下可以直接使用GNU / Linux环境而不需要虚拟机或双系统配置。
我们这里将会使用 WSL1 而无视最新的 WSL2 原因如下:
Why WSL 1 instead of WSL 2?
还有,这个:

FeatureWSL 1WSL 2
Integration between Windows and Linux
Fast boot times
Small resource foot print
Runs with current versions of VMware and VirtualBox
Performance across OS file systems

我承认表格有删减,不过删的是我不关注的feature
WSL 2 确实完善了如Linux内核等等,不过,似乎这些高大上的升级不仅我不会不关注,而且WSL 2更像是Macrohard贴牌的虚拟机了。

Let’s turn on (install) it !

不愧是巨硬,WSL安装设置过程过于节俭:

  • win键 + R
  • 打开 cmd
  • wsl --install
  • 重启计算机
    当然,前提是你满足:加入了Windows Insiders Program并安装Windows 10(OS构建20262或更高)的预览构建
    否则,请跟着我一步一步来。 (其实也并不复杂)
  1. 激活WSL
    以管理员身份打开Windows PowerShell
    输入命令,然后重启:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  1. 安装Linux发行版
    建议通过Microsoft商店安装,搜索WSL即可。这里,我安装了Ubuntu20.04
    Alt
    当然,你有很多选择:
  • Ubuntu 16.04 LTS

  • Ubuntu 18.04 LTS

  • Ubuntu 20.04 LTS

  • openSUSE Leap 15.1

  • SUSE Linux Enterprise Server 12 SP5

  • SUSE Linux Enterprise Server 15 SP1

  • Kali Linux

  • Debian GNU / Linux

  • Fedora Remix for WSL

  • Pengwin

  • Pengwin Enterprise

  • Alpine WSL

    but,Ubuntu他不香吗

    此外,建议安装Windows Terminal,emmm就是-挺好用就对了

Windows Terminal可以启用多个选项卡(在多个Linux命令行,Windows命令提示符,PowerShell,Azure CLI等之间快速切换),创建自定义键绑定(用于打开或关闭选项卡的快捷键,复制粘贴等),有搜索功能和自定义主题(配色方案,字体样式和大小,背景图片/模糊/透明度)。

  1. 启动Linux
    双击它
    在这里插入图片描述
    第一次使用需要设置一个用户名与密码,系统会将这一用户设定为Linux管理员,且这一用户与Windows无关,你会看到Linux注册

需要更改密码时在系统操作页输入passwd

谁会去记密码啊,直接“忘记密码啊”
Terminal下键入

wsl -d <LinuxDistributionName> -u root
passwd <WSLUsername>

系统会提示你输入新密码,输入密码。exit退出WSL


Linux

Alright,现在我们搞定了Linux 才没有
在学习C语言的编写之前,我们给Linux做一些简单的设置。
打开 Windows Terminal (cmd也可以) 输入bash
首次启动能够看见欢迎页

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 4.4.0-18362-Microsoft x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Feb  3 10:38:21 CST 2021

  System load:    0.52      Processes:              9
  Usage of /home: unknown   Users logged in:        0
  Memory usage:   59%       IPv4 address for eth2:  192.168.56.1
  Swap usage:     7%        IPv4 address for wifi0: 192.168.1.100

1 update can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable

The list of available updates is more than a week old.
To check for new updates run: sudo apt update

This message is shown once once a day. To disable it please create the
/home/<user>/.hushlogin file.

首先,为了加速软件的安装与更新,我们对默认的软件源进行更换,我这里使用的是华为Ubuntu镜像源。

# 修改sources.list文件
# 将http://archive.ubuntu.com和http://security.ubuntu.com替换成http://repo.huaweicloud.com
# 可以参考如下命令:

首先,备份是个好习惯,

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

输入密码:

[sudo] password for lavandejoey:

get √

配置新的镜像源,

sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
apt-get update
sudo apt-get upgrade

当然,也可以使用其他镜像源,覆盖/etc/apt/sources.list (反正vim编辑器(提前挖坑)谁都会我就不在这里赘述了),比如
北外(我超爱)

https://mirrors.bfsu.edu.cn/ubuntu/ focal main restricted universe multiverse
https://mirrors.bfsu.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
https://mirrors.bfsu.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
https://mirrors.bfsu.edu.cn/ubuntu/ focal-security main restricted universe multiverse

清华(还不错)

https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

阿里云

http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

It’s time for C ~

从C语言的角度,我来说一下为什么用Linux学习C。就我看来,C简直是Linux的亲生儿子,完善gcc、as、ld编译、链接工具;神奇的gdb调试平台;多样的Linux发行版······ohh,nicccccce
gcc是Linux最广泛的C/C++ 编译器,大多数Linux发行版都预装了gcc,在bash中键入gcc -v检查当前版本
·
·
·
·


Command 'gcc' not found, but can be installed with:

sudo apt install gcc

WHAT ? 好吧,显然我手上的Ubuntu20.4不属于大多数。按照提示用sudo apt install gcc安装gcc。由于刚刚我们设置了华为镜像源,很快啊,gcc安装好了。再次检查版本:

gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

get √
这里插一句,如果你偏要用Windows,还想用gcc,那,你需要安装MinGW,下载最新的MinGW,再添加MinGW的bin子目录到PATH环境变量。。。噢天哪,这真是太恶心了,不是吗!(不过你都看到这儿了为什么还会想着用Windows)



好的,这就是我们的第一部分内容。一切就绪,下一篇,我们正式开始

写 程 序

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

基于Windows10基于Linux的C语言笔记Ⅰ 的相关文章

随机推荐