[英]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 c / c++ -project in vscode relative to my workspace folder. 我想在vscode中相对于我的工作区文件夹定义我的c / c ++ -project的包含路径。 As mainfolder
has a different path on every system I work on, and I don't want to always change the configuration file. 由于mainfolder
在我工作的每个系统上都有不同的路径,我不想总是更改配置文件。
I have the following folder strucure 我有以下文件夹结构
mainfolder
/include1
/include2
/project/workspacepathofVScode
So the folder I open with vscode is workspacepathofVScode
. 所以我用vscode打开的文件夹是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: 在我的配置文件c_cpp_properties.json
我使用**/**/
从我的工作区根目录获取两个级别,包括我的两个包含文件夹,但它似乎不是正确的语法:
{
"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
? 如何定义相对于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. Vscode不直接支持相对路径,但可以从包含绝对路径的路径变量开始,然后附加相对路径。 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: include1
的完整路径应该是:
"${workspaceRoot}/../../include1"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.