Macbook pro M1 VSCode配置C++运行和debug环境

c_cpp_properties.json

command + shift + p
C/C++:编辑配置(JSON)

查看头文件路径

gcc -v -x c -E -

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/include",
                "/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1",
                "/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include",
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
                "/Library/Developer/CommandLineTools/usr/include",
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm64"
        }
    ],
    "version": 4
}

task.json

command + shift + B
选择others

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
          "label": "Build with Clang",
          "type": "shell",
          "command": "clang++",
          "args": [
            "${file}",
                  "-std=c++11",
                  "-o",
                  "${workspaceFolder}/out/${fileBasenameNoExtension}.out",
                  "-g",
                  "--debug"
          ],
          "group": {
            "kind": "build",
            "isDefault": true
          }
        }
      ]
}

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "lldb",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/out/${fileBasenameNoExtension}.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "console": "externalTerminal",
            "MIMode": "lldb"
        }
    ]
}

settings.json

{
    "C_Cpp.updateChannel": "Insiders",
    "leetcode.endpoint": "leetcode-cn",
    "leetcode.defaultLanguage": "cpp",
    "leetcode.workspaceFolder": "/Users/whois/leetcode",
    "leetcode.editor.shortcuts": [
        "submit",
        "test",
        "description",
        "solution"
    ],
    "markdown.preview.fontSize": 16,
    "leetcode.hint.configWebviewMarkdown": false,
    "leetcode.hint.commandShortcut": false,
    "leetcode.hint.commentDescription": false,
    "editor.fontSize": 14,
    "debug.onTaskErrors": "showErrors",
    "workbench.colorTheme": "Dracula",
    "workbench.preferredDarkColorTheme": "Dracula Soft",
    "debug.allowBreakpointsEverywhere": true,
    "explorer.confirmDelete": false,
    "editor.codeActionsOnSave": null,
    "code-runner.executorMap": {
        "cpp": "cd $dir && g++ $fileName -o /Users/whois/leetcode/out/$fileNameWithoutExt && /Users/whois/leetcode/out/$fileNameWithoutExt",
        "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "php": "php",
        "python": "python -u",
        "perl": "perl",
        "perl6": "perl6",
        "ruby": "ruby",
        "go": "go run",
        "lua": "lua",
        "groovy": "groovy",
        "powershell": "powershell -ExecutionPolicy ByPass -File",
        "bat": "cmd /c",
        "shellscript": "bash",
        "fsharp": "fsi",
        "csharp": "scriptcs",
        "vbscript": "cscript //Nologo",
        "typescript": "ts-node",
        "coffeescript": "coffee",
        "scala": "scala",
        "swift": "swift",
        "julia": "julia",
        "crystal": "crystal",
        "ocaml": "ocaml",
        "r": "Rscript",
        "applescript": "osascript",
        "clojure": "lein exec",
        "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
        "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
        "racket": "racket",
        "scheme": "csi -script",
        "ahk": "autohotkey",
        "autoit": "autoit3",
        "dart": "dart",
        "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
        "haskell": "runhaskell",
        "nim": "nim compile --verbosity:0 --hints:off --run",
        "lisp": "sbcl --script",
        "kit": "kitc --run",
        "v": "v run",
        "sass": "sass --style expanded",
        "scss": "scss --style expanded",
        "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
        "FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
    }
}

给文件头部和函数添加注释

安装koroFileHeader插件,然后进入首选项- 设置里搜索 fileheader 进行配置,不配置可以使用默认的。

自动换行

settings.json中加入

"editor.wordWrap": "on",
"editor.wordWrapColumn": 150,

配置自动生成代码片段

code -> 首选项 -> 用户片段

输入 c_cpp_header

"C C++ Header": {
        "scope": "c, cpp",
        "prefix": "header",
        "description": "Add #ifndef, #define and #endif",
        "body": [
            "#ifndef ${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H",
            "#define ${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H",
            "",
            "$0",
            "",
            "#endif"
        ]
    }

再来个

"Print to console": {
		"prefix": "cpp",//触发条件
		"body": [  // 模板内容
			"#include <iostream>",
			"",
			"using namespace std;",
			"",
			"int main()",
			"{",
			"    $0",
			"    return 0;",
			"}",
			"",
		],
		"description": " for cpp template"
	}
  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值