搭建vscode的c++环境

参考链接:http://code.visualstudio.com/docs/languages/cpp


(此次操作实在mac中进行,其他系统也可参考)


打开vscode,在应用商店搜索cpptools,下载并重新加载vscode


打开或者新建一个含有c++文件的workspace,即包含cpp文件的目录


shift+command+p输入C/Cpp: Edit Configurations

搭建vscode的c++环境_第1张图片

此时,在workspace中自动生成了.vscode目录并生成c_cpp_properties.json文件:

 "configurations": [ { 

 "name": "Mac", 

 "includePath": [ "/usr/include", "/usr/local/include" ], 

 "browse": { 

 "limitSymbolsToIncludedHeaders": true,

 "databaseFilename": ""

 } 

 } ]

}

把要用到的库的路径添加到"includePath"属性对应的数组中


shift+command+p输入Tasks: Configure Task Runner,选择others


此时.vscode目录下生成了tasks.json文件:

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

 // for the documentation about the tasks.json format 

 "version": "0.1.0",

 "command": "g++", 

 "isShellCommand": true, 

 "args": ["-g","helloWorld.cpp"],

 "showOutput": "always"

}

把运行程序时在终端输入的命令和参数对应于"command"和"args"的值,

输入shift+command+b,便可构建成功,生成可执行文件a.out


如果需要调试功能,则选择debug窗口点击设置图标

搭建vscode的c++环境_第2张图片

此时,生成launch.json文件

 "version": "0.2.0", 

 "configurations": [ {

 "name": "C++ Launch", 

 "type": "cppdbg", 

 "request": "launch", 

 "program": "${workspaceRoot}/a.out", 

 "args": [], "stopAtEntry": false, 

 "cwd": "${workspaceRoot}",

 "environment": [], 

 "externalConsole": true, 

 "osx": { 

 "MIMode": "lldb" 

 } 

 }, {

 "name": "C++ Attach", 

 "type": "cppdbg",

 "request": "attach", 

 "program": "${workspaceRoot}/a.out", 

 "processId": "${command:pickProcess}", 

 "osx": { 

 "MIMode": "lldb" 

 } 

 }

 ]}

对应的,修改相关属性的值


如果想实现构建并执行的功能,

需在task.json中的“tasks”属性定义task的名字,并在launch.json中添加“preLaunchTask“属性,对应的值为该task name,

即可实现

你可能感兴趣的:(搭建vscode的c++环境)