简体   繁体   中英

Set include paths of c/c++-project relative to workspace path in Visual Studio Code (.json configuration)

I'd like to define the include paths of my / -project in relative to my workspace folder. As mainfolder has a different path on every system I work on, and I don't want to always change the configuration file.

I have the following folder strucure

mainfolder
   /include1
   /include2
   /project/workspacepathofVScode

So the folder I open with vscode is workspacepathofVScode .

In my configuration file c_cpp_properties.json I used **/**/ to get from my workspace root two levels up, to include my two include folders, but it does not seem to be the correct syntax:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "**/**/include1",
                "**/**/include2",
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "path": [
                    "${workspaceRoot}",
                    "**/**/include1",
                    "**/**/include2",
                ]
            }
        }
    ],
    "version": 2
}

How can I define the include paths relative to workspacepathofVScode ? If it is not possible the way I thought, do you know any workaround?

Vscode doesn't support relative paths directly, but it is possible to start with a path variable containing an absolute path and then append a relative path. See the following bug discussion: Unable to resolve includes with relative paths

So for the presented case of paths thats should be relative to the workspace path, start with the workspace path variable and use ".." instead of "**" to navigate to parent folders.

The complete path for include1 should be:

"${workspaceRoot}/../../include1"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM