hello world
环境
- windows 10以上电脑一台(搭建好wsl环境)
可参照https://blog.csdn.net/u011215927/article/details/137556436?spm=1001.2014.3001.5502这篇文章进行搭建 - vscode
- ubuntu 20.04
vscode 打开linux环境
有两种方式
第一种方式
- windows打开wsl
- 输入code .
- 打开成功
第二种方式
- 直接打开vscode
- 点击左下角绿色图标
- 点击connect to wsl
这里建议使用第一种方式,快速些
编写代码
点击new file,创建一个文件,保存名字为test.c
#include <stdio.h>
int main()
{
printf("hello world!\n");
return 0;
}
找到terminal,输入命令行进行编译
- 使用cd指令切换到对应的文件目录
- 输入以下指令
gcc -o test test.c
- 报错 command “gcc” not found
解决方式:
> sudo apt-get update
> sudo apt install gcc
- 继续编译并允许
gcc -o test test.c
./test
- 成功输出