參考:http://blog.csdn.net/c_duoduo/article/details/51615381
https://cfhm.github.io/2017/09/16/vscode-2/
https://www.zhihu.com/question/30315894
日期:2018-03-16罐氨,vscode版本:1.21.1巢墅,mingw-w64版本7.2.0
1.安裝拓展:C/C++(微軟官方)、Code Runner
2.安裝軟件:mingw-w64(安裝時(shí)把“架構(gòu)”設(shè)置為x86_x64,然后設(shè)置一下路徑株汉,其他保持默認(rèn))
3.創(chuàng)建文件夾,在文件夾下編程
1)修改launch.json為://這個(gè)只用c試驗(yàn)了一下調(diào)試蹬蚁,沒有用cpp試驗(yàn)
{
? ? "version": "0.2.0",
? ? "configurations": [
? ? ? ? {
? ? ? ? ? ? "name": "C Launch (GDB)",? ? ? ? ? ? ? ? // 配置名稱打月,將會(huì)在啟動(dòng)配置的下拉菜單中顯示
? ? ? ? ? ? "type": "cppdbg",? ? ? ? ? ? ? ? ? ? ? ? ? // 配置類型,這里只能為cppdbg
? ? ? ? ? ? "request": "launch",? ? ? ? ? ? ? ? ? ? ? ? // 請(qǐng)求配置類型湿硝,可以為launch(啟動(dòng))或attach(附加)
? ? ? ? ? ? "targetArchitecture": "x86",? ? ? ? ? ? ? ? // 生成目標(biāo)架構(gòu)薪前,一般為x86或x64,可以為x86, arm, arm64, mips, x64, amd64, x86_64
? ? ? ? ? ? "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", // 將要進(jìn)行調(diào)試的程序的路徑
? ? ? ? ? ? "miDebuggerPath":"D:\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev1\\mingw64\\bin\\gdb.exe", // miDebugger的路徑关斜,注意這里要與MinGw的路徑對(duì)應(yīng)
? ? ? ? ? ? "args": [],? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 程序調(diào)試時(shí)傳遞給程序的命令行參數(shù)示括,一般設(shè)為空即可
? ? ? ? ? ? "stopAtEntry": true,? ? ? ? ? ? ? ? ? ? ? // 設(shè)為true時(shí)程序?qū)和T诔绦蛉肟谔帲话阍O(shè)置為false
? ? ? ? ? ? "cwd": "${workspaceRoot}",? ? ? ? ? ? ? ? ? // 調(diào)試程序時(shí)的工作目錄痢畜,一般為${workspaceRoot}即代碼所在目錄
? ? ? ? ? ? "externalConsole": true,? ? ? ? ? ? ? ? ? ? // 調(diào)試時(shí)是否顯示控制臺(tái)窗口垛膝,一般設(shè)置為true顯示控制臺(tái)
? ? ? ? ? ? "preLaunchTask": "Compile" ? ? ? ? ? ? ? ? ? // 調(diào)試會(huì)話開始前執(zhí)行的任務(wù),一般為編譯程序丁稀。與tasks.json的label相對(duì)應(yīng)
? ? ? ? }
? ? ]
}
2)修改tasks.json為://這個(gè)只用c試驗(yàn)了一下調(diào)試吼拥,沒有用cpp試驗(yàn)
{
? ? // See https://go.microsoft.com/fwlink/?LinkId=733558
? ? // for the documentation about the tasks.json format
? ? "version": "2.0.0",
? ? "tasks": [
? ? ? ? {
? ? ? ? ? ? "label": "Compile",
? ? ? ? ? ? "type": "shell",
? ? ? ? ? ? "command": "gcc",
? ? ? ? ? ? "args": [
? ? ? ? ? ? ? ? "${file}",
? ? ? ? ? ? ? ? "-o", // 指定輸出文件名,不加該參數(shù)則默認(rèn)輸出a.exe
? ? ? ? ? ? ? ? "${fileDirname}\\${fileBasenameNoExtension}.exe",//這里如果寫的是${file}.exe則test.c會(huì)生成test.c.exe
? ? ? ? ? ? ? ? "-g", // 生成和調(diào)試有關(guān)的信息
? ? ? ? ? ? ? ? "-Wall", // 開啟額外警告
? ? ? ? ? ? ? ? "-static-libgcc", // 靜態(tài)鏈接
? ? ? ? ? ? ? ? // "-fcolor-diagnostics",
? ? ? ? ? ? ? ? // "--target=x86_64-w64-mingw", // 默認(rèn)target為msvc线衫,不加這一條就會(huì)找不到頭文件
? ? ? ? ? ? ? ? // "-std=c11" // C語言最新標(biāo)準(zhǔn)為c11凿可,或根據(jù)自己的需要進(jìn)行修改
? ? ? ? ? ? ], // 編譯命令參數(shù)
? ? ? ? ? ? "group": {
? ? ? ? ? ? ? ? "kind": "build",
? ? ? ? ? ? ? ? "isDefault": true // 設(shè)為false可做到一個(gè)tasks.json配置多個(gè)編譯指令,需要自己修改本文件桶雀,我這里不多提
? ? ? ? ? ? },
? ? ? ? ? ? "presentation": {
? ? ? ? ? ? ? ? "echo": true,
? ? ? ? ? ? ? ? "reveal": "always", // 在“終端”中顯示編譯信息的策略矿酵,可以為always,silent矗积,never全肮。具體參見VSC的文檔
? ? ? ? ? ? ? ? "focus": false, // 設(shè)為true后可以使執(zhí)行task時(shí)焦點(diǎn)聚集在終端,但對(duì)編譯c和c++來說棘捣,設(shè)為true沒有意義
? ? ? ? ? ? ? ? "panel": "shared" // 不同的文件的編譯信息共享一個(gè)終端面板
? ? ? ? ? ? },
? ? ? ? ? ? "problemMatcher":"$gcc" // 如果你不使用clang辜腺,去掉前面的注釋符,并在上一條之后加個(gè)逗號(hào)。照著我的教程做的不需要改(也可以把這行刪去)
? ? ? ? }
? ? ]
}
3)修改c_cpp_properties.json為://includePath是解決找不到.h文件的問題评疗,把自己的.h文件的路徑加進(jìn)去测砂,這里不能識(shí)別子目錄,所以要手動(dòng)添加所有子目錄
{
? ? "configurations": [
? ? ? ? {
? ? ? ? ? ? "name": "Win32",
? ? ? ? ? ? "includePath": [
? ? ? ? ? ? ? ? "D:\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev1\\mingw64\\include",
? ? ? ? ? ? ? ? "D:\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev1\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\7.2.0\\include",
? ? ? ? ? ? ? ? "${workspaceRoot}",
? ? ? ? ? ? ? ? "D:/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/tr1",
? ? ? ? ? ? ? ? "D:/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++"
? ? ? ? ? ? ],
? ? ? ? ? ? "defines": [
? ? ? ? ? ? ? ? "_DEBUG",
? ? ? ? ? ? ? ? "UNICODE",
? ? ? ? ? ? ? ? "_UNICODE"
? ? ? ? ? ? ],
? ? ? ? ? ? "intelliSenseMode": "msvc-x64",
? ? ? ? ? ? "browse": {
? ? ? ? ? ? ? ? "path": [
? ? ? ? ? ? ? ? ? ? "D:\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev1\\mingw64\\include",
? ? ? ? ? ? ? ? ? ? "D:\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev1\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\7.2.0\\include",
? ? ? ? ? ? ? ? ? ? "${workspaceRoot}",
? ? ? ? ? ? ? ? ? ? "D:/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/tr1",
? ? ? ? ? ? ? ? ? ? "D:/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++"
? ? ? ? ? ? ? ? ],
? ? ? ? ? ? ? ? "limitSymbolsToIncludedHeaders": true,
? ? ? ? ? ? ? ? "databaseFilename": ""
? ? ? ? ? ? }
? ? ? ? }
? ? ],
? ? "version": 3
}
4)修改工作區(qū)設(shè)置為://有一些設(shè)置和c/cpp無關(guān)
{
? ? "files.defaultLanguage": "cpp", // ctrl+N新建文件后默認(rèn)的語言
? ? "code-runner.saveFileBeforeRun": true, // run code前保存
? ? "code-runner.preserveFocus": true, // 若為false百匆,run code后光標(biāo)會(huì)聚焦到終端上砌些。如果需要頻繁輸入數(shù)據(jù)可設(shè)為false
? ? "code-runner.clearPreviousOutput": false, // 每次run code前清空屬于code runner的終端消息
? ? "C_Cpp.intelliSenseEngine": "Default", // 可以為Default或Tag Parser,后者較老加匈,功能較簡(jiǎn)單存璃。具體差別參考cpptools插件文檔
? ? "editor.formatOnType": true, // 輸入時(shí)就進(jìn)行格式化,默認(rèn)觸發(fā)字符較少雕拼,分號(hào)可以觸發(fā)
? ? "editor.snippetSuggestions": "top" // snippets代碼優(yōu)先顯示補(bǔ)全
}
5)修改用戶設(shè)置為://有一些設(shè)置和c/cpp無關(guān)
{
? ? "git.ignoreMissingGitWarning": true,
? ? "workbench.colorTheme": "Blackboard",
? ? "files.autoSave": "afterDelay",
? ? "editor.renderWhitespace": "none",
? ? "files.insertFinalNewline": true,
? ? "files.trimFinalNewlines": true,
? ? "workbench.startupEditor": "newUntitledFile",
? ? "workbench.activityBar.visible": true,
}