vscode编译器使用问题

Q:vscode新建cmake项目ctrl左键无法索引头文件?
A:生成c_cpp_properties.json文件

  • 打开命令面板ctrl+shift+p,输入[c/c++:]edit configuration(UI)[c/c++:]edit configuration(JSON)即可生成;
  • 添加includePath,例如:
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include",
                "/path/to/thirdparty/include"
            ],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

Q:ctrl+shift+b编译后自动编译,没跳转编译选项是为什么?
A:配置./vscode/task.json,修改group中的"isDeflaut":false;

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": false  //改这里
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
posted @ 2024-10-30 13:12  正明小佐  阅读(7)  评论(0编辑  收藏  举报