|
| 1 | +# Windows Subsystem for Linux |
| 2 | + |
| 3 | +To use the Windows Subsystem for Linux with this extension you need to add a configuration to your **c_cpp_properties.json** file which adds the necessary header paths from within the WSL filesystem to the `includePath`. |
| 4 | + |
| 5 | +Select "C/Cpp: Edit Configurations" from the command palette to create the **c_cpp_properties.json** file if you haven't already. |
| 6 | + |
| 7 | +## Release |
| 8 | + |
| 9 | +For developers using Ubuntu with the current version of WSL released with the Fall Creators Update, you can add the following configuration template to your **c_cpp_properties.json** file. |
| 10 | + |
| 11 | +```json |
| 12 | +{ |
| 13 | + "name": "WSL", |
| 14 | + "intelliSenseMode": "clang-x64", |
| 15 | + "includePath": [ |
| 16 | + "${workspaceRoot}", |
| 17 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/c++/5", |
| 18 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu/c++/5", |
| 19 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/c++/5/backward", |
| 20 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include", |
| 21 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/local/include", |
| 22 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed", |
| 23 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu", |
| 24 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include" |
| 25 | + ], |
| 26 | + "defines": [ |
| 27 | + "__linux__", |
| 28 | + "__x86_64__" |
| 29 | + ], |
| 30 | + "browse": { |
| 31 | + "path": [ |
| 32 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/c++/5", |
| 33 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu/c++/5", |
| 34 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include", |
| 35 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/local/include", |
| 36 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed", |
| 37 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu", |
| 38 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/*" |
| 39 | + ], |
| 40 | + "limitSymbolsToIncludedHeaders": true, |
| 41 | + "databaseFilename": "" |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +The `includePath` above includes the system header paths that gcc uses for C++ projects and matches the output of `gcc -v -E -x c++ - < /dev/null`. The intelliSenseMode should be set to **"clang-x64"** to get WSL projects to work properly with IntelliSense. |
| 47 | + |
| 48 | +Note that `${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/` is the path to the root of the Ubuntu filesystem. This will be different if you are using a different distro. You can discover the paths to your distro's filesystem by using this handy PowerShell command: |
| 49 | + |
| 50 | +```Powershell |
| 51 | +PS R:\> ($(get-appxpackage).PackageFamilyName | findstr /i 'SUSE Ubuntu') -replace '^', "$`{localappdata`}/Packages/" |
| 52 | +
|
| 53 | +${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc |
| 54 | +${localappdata}/Packages/46932SUSE.openSUSELeap42.2_022rs5jcyhyac |
| 55 | +${localappdata}/Packages/46932SUSE.SUSELinuxEnterpriseServer12SP2_022rs5jcyhyac |
| 56 | +``` |
| 57 | + |
| 58 | +For C projects, simply remove the C++ lines: |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + "name": "WSL", |
| 63 | + "intelliSenseMode": "clang-x64", |
| 64 | + "includePath": [ |
| 65 | + "${workspaceRoot}", |
| 66 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include", |
| 67 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/local/include", |
| 68 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed", |
| 69 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu", |
| 70 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include" |
| 71 | + ], |
| 72 | + "defines": [ |
| 73 | + "__linux__", |
| 74 | + "__x86_64__" |
| 75 | + ], |
| 76 | + "browse": { |
| 77 | + "path": [ |
| 78 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include", |
| 79 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/local/include", |
| 80 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed", |
| 81 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/x86_64-linux-gnu", |
| 82 | + "${localappdata}/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/usr/include/*" |
| 83 | + ], |
| 84 | + "limitSymbolsToIncludedHeaders": true, |
| 85 | + "databaseFilename": "" |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +### Beta |
| 91 | + |
| 92 | +For developers using Bash on Ubuntu on Windows with the beta version of WSL from before the Fall Creators Update, you can add the following configuration template to your **c_cpp_properties.json** file. |
| 93 | + |
| 94 | +```json |
| 95 | +{ |
| 96 | + "name": "WSL (Beta)", |
| 97 | + "intelliSenseMode": "clang-x64", |
| 98 | + "includePath": [ |
| 99 | + "${workspaceRoot}", |
| 100 | + "${localappdata}/lxss/rootfs/usr/include/c++/5", |
| 101 | + "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5", |
| 102 | + "${localappdata}/lxss/rootfs/usr/include/c++/5/backward", |
| 103 | + "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include", |
| 104 | + "${localappdata}/lxss/rootfs/usr/local/include", |
| 105 | + "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed", |
| 106 | + "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu", |
| 107 | + "${localappdata}/lxss/rootfs/usr/include" |
| 108 | + ], |
| 109 | + "defines": [ |
| 110 | + "__linux__", |
| 111 | + "__x86_64__" |
| 112 | + ], |
| 113 | + "browse": { |
| 114 | + "path": [ |
| 115 | + "${localappdata}/lxss/rootfs/usr/include/c++/5", |
| 116 | + "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5", |
| 117 | + "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include", |
| 118 | + "${localappdata}/lxss/rootfs/usr/local/include", |
| 119 | + "${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed", |
| 120 | + "${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu", |
| 121 | + "${localappdata}/lxss/rootfs/usr/include/*" |
| 122 | + ], |
| 123 | + "limitSymbolsToIncludedHeaders": true, |
| 124 | + "databaseFilename": "" |
| 125 | + } |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +The `includePath` above includes the system header paths that gcc uses for C++ projects and matches the output of `gcc -v -E -x c++ - < /dev/null`. The intelliSenseMode should be set to **"clang-x64"** to get WSL projects to work properly with IntelliSense. |
| 130 | + |
| 131 | +Note that `${localappdata}/lxss/rootfs/` is the path to the root of the filesystem for Bash on Ubuntu on Windows. |
| 132 | + |
| 133 | +For C projects, simply remove the C++ lines as in the previous example. |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +With these configurations, you should be all set up to use the new IntelliSense engine for linting, memberlist autocomplete, and quick info (tooltips). Add `"C_Cpp.intelliSenseEngine": "Default"` to your **settings.json** file to try out the new IntelliSense engine. |
| 138 | + |
| 139 | +And remember to [heed the warnings of the Windows team about not creating or editing Linux files from a Windows app](https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/)! |
0 commit comments