無廢話,直接上步驟。c++
1) 安裝 xcode。shell
打開App Store,搜索xcode,進行下載安裝。json
2)執行命令:xcode
xcode-select --install微信
安裝命令行工具。app
3)安裝VS Code工具
https://code.visualstudio.com/spa
4) 打開vs code。打開左側擴展欄,命令行
搜索「c++」。調試
安裝該擴展。
5)打開一個保護.cpp文件的文件夾(沒有就本身建立)
此時會在當前工做空間目錄生成.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)
{ // 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。
選擇Debug: Open launch.json命令。
修改內容以下:
{ // 使用 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)開啓調試
中途可能會提醒控制終端,須要賦予權限,容許便可。
最後若是終端有相似的提示,輸入回車結束終端調用。
可能遇到的問題:
可能遇到「xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun」
這樣的報錯,終端輸入命令:
sudo xcode-select --switch /Applications/Xcode.app
更多精彩內容,關注微信訂閱號「玄魂工做室」(xuanhun521)