vscode 配置c语言编译,windows 配置vscode c 语言编译环境

用vscode打开工程目录,

首先安装这几个插件:C/C++,C/C++ Compile Run, Code Runner

然后ctrl + shift + p ,

搜索c/c++ 选择 Edit Configuration(Json),

这时工程目录应该已经生成一个.vscode文件夹,和一个c_cpp_properties.json 文件,

再新增这几个文件,launch.json, tasks.json, setting.json

对应修改文件内容如下:

c_cpp_properties.json:

{

"configurations": [

{

"name": "Win32",

"includePath": [

"${workspaceFolder}/**",

"C:\Program Files\mingw64\include" // 这里对应自己本地的c编译器的目录

],

"defines": [

"_DEBUG",

"UNICODE",

"_UNICODE"

],

"compilerPath": "C:\Program Files\mingw64\bin\gcc.exe", //同样对应本机的,下面的不用动

"cStandard": "c11",

"cppStandard": "c++17",

"intelliSenseMode": "clang-x64"

}

],

"version": 4

}

============

launch.json:

{

"version": "0.2.0",

"configurations": [

{

"name": "gcc.exe",

"type": "cppdbg",

"request": "launch",

// "program": "

math?formula=%7BworkspaceRoot%7D%2Fa.out%22%20%22program%22%3A%20%22{fileDirname}\

math?formula=%7BfileBasenameNoExtension%7D.exe%22%2C%20%22args%22%3A%20%5B%5D%2C%20%22stopAtEntry%22%3A%20false%2C%20%22cwd%22%3A%20%22{workspaceFolder}",

"environment": [],

"externalConsole": true,

"MIMode": "gdb",

"miDebuggerPath": "C:\Program Files\mingw64\bin\gdb.exe", // 对应即可

"setupCommands": [

{

"description": "gdb print",

"text": "-enable-pretty-printing",

"ignoreFailures": true

}

],

"preLaunchTask":"gcc.exe build active file"

}

]

}

==========

tasks.json:

{

"version": "2.0.0",

"command": "gcc",

"args": [

"-g",

"

math?formula=%7Bfile%7D%22%2C%20%22-o%22%2C%20%22{fileBasenameNoExtension}.exe"

],

"tasks": [

{

"type": "shell",

"label": "gcc.exe build active file",

"command":"C:\Program Files\mingw64\bin\gcc.exe", // 对应本地

"args": [

"-g",

"

math?formula=%7BworkspaceFolder%7D%5C%5C*.c%22%2C%20%22-o%22%2C%20%22{fileDirname}\

math?formula=%7BfileBasenameNoExtensin%7D.exe%22%20%5D%2C%20%22options%22%3A%20%7B%20%22cwd%22%3A%20%22C%3A%5C%5CProgram%20Files%5C%5Cmingw64%5Cbin%22%20%2F%2F%20%E5%AF%B9%E5%BA%94%E6%9C%AC%E5%9C%B0%20%7D%2C%20%22problemMatcher%22%3A%5B%20%22gcc"

],

"group": "build"

}

]

}

=============

setting.json:

{

"code-runner.runInterminal":true

}

最后设置:

左下角--settings--run in terminal 选项 勾上,重启vscode即可,支持在控制台输入scanf

mac 的同样步骤,但是无法使用terminal,有时间再看

mac 配置:

大致相同:如果是使用clang 那就换一下编译器的地址

c_cpp_properties.json:

{

"configurations": [

{

"name": "Mac",

"includePath": [

"${workspaceFolder}/**"

],

"defines": [],

"macFrameworkPath": [

"/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks"

],

"compilerPath": "/usr/bin/gcc",

"cStandard": "c11",

"cppStandard": "c++17",

"intelliSenseMode": "gcc-x64"

}

],

"version": 4

}

task.json:

{

// See https://go.microsoft.com/fwlink/?LinkId=733558

// for the documentation about the tasks.json format

"version": "2.0.0",

"tasks": [

{

"label": "gcc",

"type": "shell",

"command": "/usr/bin/gcc",

"args": [

"-g",

"${file}",

"-o",

"${fileDirname}/${fileBasenameNoExtension}.out"

],

"options": {

"cwd": "${workspaceFolder}"

},

"problemMatcher":[

"$gcc"

],

"group": {

"kind": "build",

"isDefault": true

}

}

],

"version": "2.0.0"

}

然后是插件:code-runner中打开 run interminal

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值