c_cpp_properties.json does not support environment variables in include paths
The include paths in c_cpp_properties.json does not seem to support environment variables like the following:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"$(SOME_LIBRARY)/include"
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"path": [
"/usr/include",
"/usr/local/include",
"$(SOME_LIBRARY)/include"
]
}
}
]
}
It only tells me that the header files in ${SOME_LIBRARY}/include cannot be found. I'm not sure if I do this in the right way but I may get some warning if entries in includePath do not exist as folders.
I have the same problem with %USERPROFILE% on Windows.
Since I see multiple syntaxes for environment variables in this issue, I just wanted to double check and make sure that you are specifying your variables using the following syntax: ${VARIABLE}
@bobbrow, I've tried both ${} and $(), but sadly neither seems to work.
I tested this on Linux today with the ${HOME} variable and that works for me.
- What is the expected value of
${SOME_LIBRARY}? - Are you sure it's defined in the environment that VS Code inherited?
- Are you using
"intelliSenseEngine": "Default"or"intelliSenseEngine": "Tag Parser"?
"includePath" is used by the new IntelliSense engine and is not a recursive path - which means that your #include <header.h> must be in that folder, not some sub-folder. #include <subfolder/header.h> would search "subfolder" for the header file. "browse.path" is used by the tag parser and is searched recursively.
Just a comment: I was expecting the format to be ${env:HOME} as described here for tasks.json. The ${HOME} format works for me though.
Thanks. Agreed that the syntax should be the same. Namely, ${env:VARIABLE}.
I can also confirm that ${VARIABLE} works (though not recursively but I'd consider that a feature not a bug).
It works now, thanks!
Wait, what works now? ${VARIABLE}?
There should probably be another bug tracking the fact that the syntax is different in c_cpp_properties.json vs tasks.json (and probably other stuff).
@bobbrow, should I reopen the other one?
I reopened it.
Neither ${env.VARIABLE} nor ${env:VARIABLE} works inside browse and includePath:
It would be nice also to set values with other commands like ${python.pythonPath}.
Example below doesn't work with ${env.VARIABLE} also.
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${env:PYTHON_LIB_TENSORFLOW}/include/",
"${env:PYTHON_LIB_TENSORFLOW}/include/external/nsync/public",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${env:PYTHON_LIB_TENSORFLOW}/include/",
"${env:PYTHON_LIB_TENSORFLOW}/include/external/nsync/public",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/usr/include/c++/v1",
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
VSCode Version 1.21.1 (1.21.1) 79b44aa704ce542d8ca4a3cc44cfca566e7720f1 2018-03-14T14:34:33.071Z
All three previously mentioned syntaxes ${env:ARMGCC_INCLUDE}, ${env.ARMGCC_INCLUDE} and ${ARMGCC_INCLUDE} appear to work but only with system wide variables and NOT those defined with "terminal.integrated.env.windows": { "ARMGCC_INCLUDE": "C:/...path.../include", ... } (in settings.json)
Update
If a workspace dependent variable is required I found this works
"${config:terminal.integrated.env.windows.ARMGCC_INCLUDE}"
or even
define in settings.json
"any.made.up.variable" : "value"
use in c_cpp_properties.json and / or launch.json
${config:any.made.up.variable}
NOTE: in this case the config: or older config. prefix must be used.
C/C++ for Visual Studio Code Version 0.15.0: February 15, 2018
VSCode Version 1.21.1 Windows 10, x64
@Andrew-w-w Hi, is it really works fine for you? I have issue and one of developers (as I think) said, that isn't possible :(
@r3d9u11, I responded to your issue. Take a look at the documentation I linked and let us know if that doesn't meet your needs.
I rechecked my experiments and found that custom variables only worked in launch.json and NOT c_cpp_properties.json.
The reason it appeared to work was it was so broken the edits where not being read in at all.
Sorry for the confusion.
The recent changes look very interesting although I have not had a chance to study them in detail yet.