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

c_cpp_properties.json does not support environment variables in include paths

Open renkun-ken opened this issue 9 years ago • 14 comments

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.

renkun-ken avatar May 06 '17 16:05 renkun-ken

I have the same problem with %USERPROFILE% on Windows.

dymo avatar May 07 '17 14:05 dymo

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 avatar May 08 '17 22:05 bobbrow

@bobbrow, I've tried both ${} and $(), but sadly neither seems to work.

renkun-ken avatar May 09 '17 02:05 renkun-ken

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.

bobbrow avatar May 09 '17 15:05 bobbrow

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.

oliveroxtoby avatar Jun 28 '17 12:06 oliveroxtoby

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

azydevelopment avatar Aug 29 '17 05:08 azydevelopment

It works now, thanks!

renkun-ken avatar Aug 29 '17 06:08 renkun-ken

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?

azydevelopment avatar Aug 29 '17 06:08 azydevelopment

I reopened it.

bobbrow avatar Aug 29 '17 15:08 bobbrow

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

awav avatar Mar 17 '18 17:03 awav

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 avatar Mar 19 '18 11:03 Andrew-w-w

@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 :(

R3D9477 avatar May 23 '18 19:05 R3D9477

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

bobbrow avatar May 23 '18 21:05 bobbrow

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.

Andrew-w-w avatar Jun 03 '18 23:06 Andrew-w-w