vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

c_cpp_properties.json support for environment variables defined in ~/.bashrc used in "includePath" and "compilerPath"

Open reoLantern opened this issue 1 year ago • 4 comments

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:

  1. It seems that intellisense currently doesn't recognize using environment variable in compilerPath. There are squiggles under "${env:GCC_PATH}/bin/g++".

  2. 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.

reoLantern avatar Jul 13 '23 02:07 reoLantern

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.

reoLantern avatar Jul 13 '23 03:07 reoLantern

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.

github-actions[bot] avatar Sep 17 '23 11:09 github-actions[bot]

This feature request has received enough votes to be added to our backlog.

github-actions[bot] avatar Feb 08 '24 12:02 github-actions[bot]