參考資料: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++即可。
