Vscode-cpptools: WSL Include file not found in include path

Created on 10 May 2017  路  27Comments  路  Source: microsoft/vscode-cpptools

  • VSCode Version: 1.12.1
  • C/C++Plugin Version: 0.11.0
  • OS Version: Windows 10 64-Bit with Creator update
    default

Hello, I am a bash on Ubuntu on Windows user. And I've had some problems when I was programming in C++. When I put the headers (includes) then it appeared this: "include file not found in include path". How can I fix this? I try to add "/usr/include" into it as the figure shows.
default

in c_cpp_properties.json . But it does not works.
Thank you!

Language Service bug fixed (release pending)

Most helpful comment

@eesaber I had success with the following config:

        {
            "name": "WSL",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "${workspaceRoot}",
                "${localappdata}/lxss/rootfs/usr/include/c++/5",
                "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                "${localappdata}/lxss/rootfs/usr/include/c++/5/backward",
                "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                "${localappdata}/lxss/rootfs/usr/local/include",
                "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu",
                "${localappdata}/lxss/rootfs/usr/include"
            ],
            "defines": [
                "__linux__",
                "__x86_64__"
            ],
            "browse": {
                "path": [
                    "${localappdata}/lxss/rootfs/usr/include/c++/5",
                    "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                    "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                    "${localappdata}/lxss/rootfs/usr/local/include",
                    "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                    "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu",
                    "${localappdata}/lxss/rootfs/usr/include/*"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }

An option to select clang/gcc mode on Windows is coming in the next update. I have tested it with MinGW on Windows and it works well for me. I will test it with WSL tomorrow. Watch the release notes for instructions. We'll add a FAQ for WSL with this config in it as well, since we're not going to auto-detect it for you right now.

All 27 comments

I meet the same problem also..

VSCode Version: 1.12
OS Version: windows 10 Latest Update
Steps to Reproduce:
set bash Ubuntu on win10 asthe default command window for visual code
add include path for c++ headers on WSL, such as : "C:/Users/user_name/AppData/Local/lxss/rootfs/usr/include/c++/5 " in c_cpp_properties.jason
And this won't work...visual code still can't find these c++ header for linux sub-system.

I just had a similar issue trying to use VSCode with MinGW on Windows 10 (no Ubuntu on Windows in my case). And I have been able to solve it by adding the include paths to the browse.path property rather than just to the includePath property. So in your case

"browse": { 
    "path": [
        "/usr/include",
        "/usr/local/include"
    ],

It seems to be an inconsistency between the recommended property to edit (includePath) and the one that is being used by IntelliSense by default (browse.path). See the FAQ here for more info (note that the default intelliSenseEngine in the VSCode settings is the Tag Parser).

@JirkaValtr Thanks for your solution. I am also using VSCode with MinGW on Windows 10. After I added the paths to the browse.path, I found that the C/C++ plugin complains that functions like 'fprintf'. 'fopen' are not defined although I did include \(I tried both of them, they both don't work). Have you ever encountered the similar situations? Thanks.

VSCode Version: 1.12.2
C/C++Plugin Version: 0.11.1

image

I tried to replicate your situation, but the following code ran fine for me, and the C/C++ plugin didn't complain about anything.

#include <cstdio>
#include <cstdlib>

int main() {
    FILE* fo = fopen("myfile.txt","w");
    if (fo != NULL) fclose(fo);
}

@zinechant What version of gcc and/or libc++ are you using?

@JirkaValtr Thanks a lot for your reply. I have no clue why it doesn't work in my situation.
@sean-mcmanus I am using MinGW with g++ V5.3.0. I don't know how to check the libc++ version that MinGW uses. From a quick search, it seems MinGW built against libmsvcrt.a rather than glibc.

@zinechant Probably there are more paths you need to add. If you open the #include files to see what squiggles they show, that might help diagnose the problem. I don't think we've tested on WSL yet, so there might be issues.

Since you're on Windows, the IntelliSense mode defaults to Microsoft mode, not gcc/clang mode.

We don't expose any controls to switch this right now, but you can see if replacing %userprofile%\.vscode\extensions\ms-vscode.cpptools-0.11.1\bin\msvc.64.intel.json with msvc.64.linux.json fixes it.

@bobbrow Thanks for your reply. It still not works. Will the control which can switch to gcc mode become a setting option in future release?

Yes, it is on our backlog.

That's great to hear...i am looking forward windows' version of visual code cpptools will support bash on ubuntu gcc mode

@eesaber I had success with the following config:

        {
            "name": "WSL",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "${workspaceRoot}",
                "${localappdata}/lxss/rootfs/usr/include/c++/5",
                "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                "${localappdata}/lxss/rootfs/usr/include/c++/5/backward",
                "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                "${localappdata}/lxss/rootfs/usr/local/include",
                "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu",
                "${localappdata}/lxss/rootfs/usr/include"
            ],
            "defines": [
                "__linux__",
                "__x86_64__"
            ],
            "browse": {
                "path": [
                    "${localappdata}/lxss/rootfs/usr/include/c++/5",
                    "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                    "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                    "${localappdata}/lxss/rootfs/usr/local/include",
                    "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                    "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu",
                    "${localappdata}/lxss/rootfs/usr/include/*"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }

An option to select clang/gcc mode on Windows is coming in the next update. I have tested it with MinGW on Windows and it works well for me. I will test it with WSL tomorrow. Watch the release notes for instructions. We'll add a FAQ for WSL with this config in it as well, since we're not going to auto-detect it for you right now.

@bobbrow I success too. Thank you so much!

I updated the config above after doing some testing with WSL. It now includes the new intelliSenseMode setting which was added in version 0.12.0. I tested this config using the "C_Cpp.intelliSenseEngine": "Default" setting and can confirm that semantic autocomplete, quick info tooltips, and linting are working as expected.

So...where is clang actually running here if I am using VSCode on windows10?

Thanks

@lurium Our clang-x64 mode doesn't run clang, it just makes our parser compatible with it. Is that what you're referring to?

Yes, though I'm curious as to how you did this specifically.

Is this behavior different if I run VSCode from linux?

Thank you

@lurium clang-x64 mode theoretically should behave the same on Windows and Linux, but parts of our code are compiled differently and use different library implementations on Windows/Linux, so there may be unintended differences (i.e. bugs on a particular platform, just like any other feature).

This is one of the top links from google, and the link is out of date.
Here's the most recent config and a little tutorial:

1) Ctrl+Shift+P then type C/Cpp: Edit Configurations
2) Add the following to the config file:

{
            "name": "WSL",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "${workspaceRoot}",
                "${localappdata}/lxss/rootfs/usr/include/c++/5",
                "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                "${localappdata}/lxss/rootfs/usr/include/c++/5/backward",
                "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                "${localappdata}/lxss/rootfs/usr/local/include",
                "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu",
                "${localappdata}/lxss/rootfs/usr/include"
            ],
            "defines": [
                "__linux__",
                "__x86_64__"
            ],
            "browse": {
                "path": [
                    "${localappdata}/lxss/rootfs/usr/include/c++/5",
                    "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                    "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                    "${localappdata}/lxss/rootfs/usr/local/include",
                    "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                    "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu",
                    "${localappdata}/lxss/rootfs/usr/include/*"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }

3) Ctrl+Shift+P then type C/Cpp: Select a Configuration
4) Select WSL

Happy coding.

@timothyr can you clarify why you think the WSL documentation is out of date? What you've posted looks like the "old" WSL config which is also in the documentation.

@bobbrow I checked again and you're right, it's included. I missed it the first time because WSL has been out of beta for >9 months. Perhaps the labels should be switched. The current "Beta" instructions are working for the release, and the current "Release" instructions are deprecated.

I use Ubuntu App for WSL with VSC, and I've followed cpptools WSL but still have the problem "Include Error".
I've also checked the folders in Windows, and indeed there exists these files.
Did I missed something?

{
    "configurations": [
        {
            "name": "WSL",
            "intelliSenseMode": "clang-x64",
            "includePath": [
                "${workspaceRoot}",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/c++/5",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/c++/5/backward",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/local/include",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu",
                "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include"
            ],
            "defines": [
                "__linux__",
                "__x86_64__"
            ],
            "browse": {
                "path": [
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/c++/5",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu/c++/5",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/local/include",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu",
                    "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/*"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 3
}


@ab37695543xs I'm not able to repro the issue with my WSL setup and your c_cpp_properties.json settings. I'm not sure what the difference is...maybe your WSL version and/or the compiler/libs installed? I have clang-3.9 installed. If you install the insiders build (cpptools-win32.vsix at https://github.com/Microsoft/vscode-cpptools/releases/download/v0.16.0-insiders/ ) it will have more logging (the "sending compilation args" output) if you temporarily set the loggingLevel to the hidden value of "6", but the new compilerPath option doesn't work on Windows or WSL with that version (actually, WSL-basec compilerPath got post-poned till April, but Windows-based clang/gcc should work for March).

Ok, I installed the LLVM 6.0.0 in Windows and added the following to my VSC user settings.
Howerver, it seems not working, do I need to add any other setting or install somthing else?
Or... maybe I should install clang in WSL?

@ab37695543xs, are you using a Windows Insiders build? We are tracking another WSL issue that looks similar to yours here: #1694

@bobbrow Yes, I'm using Windows Insider 17115, too

Was this page helpful?
0 / 5 - 0 ratings