無廢話--Mac OS, VS Code 搭建c/c++基本開發(fā)環(huán)境

無廢話,直接上步驟。

1) 安裝 xcode。

打開App Store,搜索xcode,進行下載安裝。

image

2)執(zhí)行命令:

xcode-select --install

image

安裝命令行工具。

3)安裝VS Code

https://code.visualstudio.com/

image

4) 打開vs code。打開左側(cè)擴展欄,

image

搜索“c++”。

cpp-extension.png

安裝該擴展。

5)打開一個保護.cpp文件的文件夾(沒有就自己創(chuàng)建)

“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

修改內(nèi)容如下:

{
    // 使用 IntelliSense 了解相關(guān)屬性。 
    // 懸停以查看現(xiàn)有屬性的描述。
    // 欲了解更多信息,請訪問: 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)開啟調(diào)試

image
image

中途可能會提醒控制終端,需要賦予權(quán)限,允許即可。

image

最后如果終端有類似的提示,輸入回車結(jié)束終端調(diào)用。

可能遇到的問題

可能遇到“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

更多精彩內(nèi)容,關(guān)注微信訂閱號“玄魂工作室”(xuanhun521)

image
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容