Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL Include file not found in include path #710

Closed
eesaber opened this issue May 10, 2017 · 27 comments
Closed

WSL Include file not found in include path #710

eesaber opened this issue May 10, 2017 · 27 comments
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service

Comments

@eesaber
Copy link

eesaber commented May 10, 2017

  • 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!

@SkyRiderMike
Copy link

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.

@JirkaValtr
Copy link

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

@zinechant
Copy link

zinechant commented May 21, 2017

@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 <cstdio> or <stdio.h>(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

@JirkaValtr
Copy link

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);
}

@sean-mcmanus
Copy link
Contributor

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

@zinechant
Copy link

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

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented May 22, 2017

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

@bobbrow
Copy link
Member

bobbrow commented May 22, 2017

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.

@eesaber
Copy link
Author

eesaber commented May 23, 2017

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

@bobbrow
Copy link
Member

bobbrow commented May 23, 2017

Yes, it is on our backlog.

@SkyRiderMike
Copy link

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

@bobbrow
Copy link
Member

bobbrow commented Jun 15, 2017

@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 bobbrow added the fixed Check the Milestone for the release in which the fix is or will be available. label Jun 15, 2017
@eesaber
Copy link
Author

eesaber commented Jun 15, 2017

@bobbrow I success too. Thank you so much!

@bobbrow
Copy link
Member

bobbrow commented Jun 28, 2017

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.

@bobbrow bobbrow closed this as completed Jun 28, 2017
@lurium
Copy link

lurium commented Oct 11, 2017

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

Thanks

@sean-mcmanus
Copy link
Contributor

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

@lurium
Copy link

lurium commented Oct 11, 2017

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

Is this behavior different if I run VSCode from linux?

Thank you

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Oct 11, 2017

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

@CoenraadS
Copy link

For people like me who run across this topic from google, see: https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/Windows%20Subsystem%20for%20Linux.md

@timothyr
Copy link

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.

@bobbrow
Copy link
Member

bobbrow commented Feb 20, 2018

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

@timothyr
Copy link

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

@ab37695543xs
Copy link

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
}


@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Mar 15, 2018

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

@ab37695543xs
Copy link

ab37695543xs commented Mar 17, 2018

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?

@bobbrow
Copy link
Member

bobbrow commented Mar 19, 2018

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

@ab37695543xs
Copy link

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

@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Projects
None yet
Development

No branches or pull requests

9 participants