废话,直接上步骤。
1) 安装 xcode。
打开App Store,搜索xcode,进行下载安装。
image
2)执行命令:
xcode-select --install
image
安装命令行工具。
3)安装VS Code
https://code.visualstudio.com/
image
4) 打开vs code。打开左侧扩展栏,
image
搜索“c++”。
cpp-extension.png
安装该扩展。
5)打开一个保护.cpp文件的文件夹(没有就自己创建)
“command+shift+p”打开命令行工具窗口,输入或者选择“
Edit Configurations”命令。
QQ20181101-152136@2x.png
此时会在当前工作空间目录生成.vscode配置目录,同时在配置目录会生成一个c_cpp_properties.json文件。
配置include目录:
{ "configurations": [ { "name": "Mac", "includePath": [ "${workspaceFolder}/**", "/Library/Developer/CommandLineTools/usr/include/c++/v1", "/usr/local/include", "/Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/include", "/Library/Developer/CommandLineTools/usr/include", "/usr/include" ], "defines": [], "macFrameworkPath": [ "/System/Library/Frameworks", "/Library/Frameworks" ], "compilerPath": "/usr/bin/clang", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" } ], "version": 4}
6)
“command+shift+p”打开命令行工具窗口,输入或者选择“Tasks: Configure Task”
QQ20181101-161752@2x.png
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "c++", "command": "clang++", "type": "shell", "args": [ "./c++/hello.cpp", "-std=c++11", "-g" ], "presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "shared" } } ] }
7)配置launch.json。
“command+shift+p”打开命令行工具窗口,输入或者
选择Debug: Open launch.json命令。
image
修改内容如下:
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "c/c++ Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/a.out", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "lldb", "preLaunchTask":"c++" } ] }
8)开启调试
image
image
中途可能会提醒控制终端,需要赋予权限,允许即可。
image
作者:玄魂
链接:https://www.jianshu.com/p/f106724671bb