参考资料:https://www.cnblogs.com/2018shawn/p/13580555.html
参考资料:https://blog.csdn.net/deaidai/article/details/82955010
1.首先在appstore中下载xcode
2.接下来进入在windows中下载vscode的dmg版本并拷贝到mac盘上(如果能够在mac系统里完成下载那是最好的,但是我一次也没成功过)
3.打开vscode的扩展市场,下载两款插件C/C++和C/C++ Clang Command Adapter
4.接下来打开一个文件夹,作为你的编译环境。
在文件夹内创建.vscode文件夹
下创建launch.json以及tasks.json
lanuch.json
1 { 2 // 使用 IntelliSense 了解相关属性。 3 // 悬停以查看现有属性的描述。 4 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 5 "version": "0.2.0", 6 "configurations": [ 7 { 8 "name": "启动C++", 9 "type": "cppdbg", 10 "request": "launch", 11 "program": "${workspaceFolder}/${fileBasenameNoExtension}.out", 12 "args": [], 13 "stopAtEntry": false, 14 "cwd": "${workspaceFolder}", 15 "environment": [], 16 "externalConsole": true, 17 "MIMode": "lldb", 18 "preLaunchTask": "Run Cpp" 19 } 20 ] 21 }
tasks.json
1 { 2 // See https://go.microsoft.com/fwlink/?LinkId=733558 3 // for the documentation about the tasks.json format 4 "version": "2.0.0", 5 "tasks": [ 6 { 7 "label": "Run Cpp", 8 "type": "shell", 9 "command": "g++", 10 "args": [ 11 "-g", 12 "${file}", 13 "-o", 14 "${fileBasenameNoExtension}.out" 15 ], 16 "group": { 17 "kind":"build", 18 "isDefault": true 19 }, 20 21 }, 22 { 23 "label": "Open Terminal", 24 "type": "shell", 25 "command": "osascript -e ‘tell application \"Terminal\"\ndo script \"echo hello\"\nend tell‘", 26 "problemMatcher": [] 27 } 28 29 ] 30 }
其中有几个关键信息。
launch.json中"preLaunchTask": "Run Cpp"即为运行前先运行task的编译程序,就不用再手动编译了。"Run Cpp"是在tasks.json里设置的label。
launch.json中"externalConsole": true是外显终端,目的在于不在内置终端中运行。
5.接下来是激活终端。
首先点开左侧调试运行栏,点击启动,然后会出现终端并且需要输入密码的情况。如果没有,在终端中输入
DevToolsSecurity -enable
6.然后在vscode的命令面板(用cmd+shift+p呼出)输入Run Task,点击Open Terminal。在打开的终端前点击OK!即可完成全部的激活。
7.新建一个cpp文件,写一段代码,然后按左侧的调试界面,点击启动C++即可。
原文:https://www.cnblogs.com/dormin/p/14617817.html