基础配置
准备
安装gcc
// 更新源
sudo apt-get update
// 安装
sudo apt-get install build-essential gdb
// 检查一下
gcc -v
安装并配置vscode
先在windows上下载安装vscode
打开ubuntu
// 打开当前目录 自动安装
code .
安装c/c++扩展
测试一下
在当前目录新建hello-world.c文件
#include <stdio.h>
int main()
{
  printf("Hello, world!\n");
  return 0;
}
在终端编译并运行
gcc hello-world.c -o hello-world && ./hello-world
可以看到成功输出了Hello, world!
进阶配置 懒人必备
vscode代码片段
打开vscode 菜单栏->文件->首选项->配置用户代码片段->新建c
{
  "main template": {
    "prefix": "temp",
    "body": [
      "#include <stdio.h>",
      "",
      "int main()",
      "{",
      "  $1",
      "  return 0;",
      "}"
    ],
    "description": "main template"
  }
}
新建一个c文件 输入temp 就可以使用了
简化编译运行命令
打开.bashrc文件
code ~/.bashrc
添加到.bashrc文件最后一行
alias c='_c(){ gcc $1 -o ${1%.*}; ./${1%.*};};_c'
保存关闭并执行
source ~/.bashrc
将之前的命令
gcc hello-world.c -o hello-world && ./hello-world
替换为
c hello-world.c
搞定~
												
																	
评论
还没有任何评论,你来说两句吧!