vscode-cpptools
vscode-cpptools copied to clipboard
c_cpp_properties.json support for environment variables defined in ~/.bashrc used in "includePath" and "compilerPath"
Feature Request
I have a project compiled with g++. I have two Windows PCs, with one connected to local WSL and the other to a remote server. The path to g++ and the path of a third-party library needed in the includePath are different on the two devices.
So I set different environment variables in .bashrc on both devices:
export GCC_PATH = /path/to/gcc
export MY_LIB_PATH = /path/to/my/lib/
In c_cpp_properties.json, use the following settings:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${env:MY_LIB_PATH}/include"
],
"compilerPath": "${env:GCC_PATH}/bin/g++",
"cStandard": "gnu23",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
Then the following problems occured:
-
It seems that intellisense currently doesn't recognize using environment variable in compilerPath. There are squiggles under "${env:GCC_PATH}/bin/g++".
-
Although there are no squiggles under "${env:MY_LIB_PATH}/include" in includePath, the intellisense still can't find the header that needs to be included in the .cpp file. So when I open a .cpp file, squiggles appear.
This should not be due to a flaw in defining environment variables in .bashrc, as this link suggests that VSCode should now auto-detect environment variables in .bashrc.
I noticed and browsed a lot of issues about environment variable support, but still can't find a solution for this problem, so I consider it as a request that may be added.
Update: to set envs directly in c_cpp_properties works fine, as below:
{
"env": {
"GCC_PATH" : "/path/to/gcc",
"MY_LIB_PATH" : "/path/to/my/lib/"
},
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${env:MY_LIB_PATH}/include"
],
"compilerPath": "${env:GCC_PATH}/bin/g++",
"defines": [],
"cStandard": "gnu23",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
But this method does not apply to my syntax, since I want to prepare environment on TWO DEVICES.
Note: Related on Stack Overflow: How to set different compiler path and includePath in c_cpp_properties.json on different devices for different projects in VSCode?
This feature request is being closed due to insufficient upvotes. Please leave a 👍-upvote or 👎-downvote reaction on the issue to help us prioritize it. When enough upvotes are received, this issue will be eligible for our backlog.
This feature request has received enough votes to be added to our backlog.