Impossible to create project with WSL
Using C++ and WSL in VS Code https://code.visualstudio.com/docs/cpp/config-wsl
1.Following the tutorial exactly, it fails at: code . This doesn't create a workspace if projects folder was directly created under user's home folder. Hence, you can't continue on with C/C++: Edit configurations… The IDE will do nothing.
I suspect this is because VSCode should not touch files directly in the WSL
- Following the tutorial exactly, but placing folder helloworld in the Windows file system: /mnt/f/dev/wslprojects/ Tutorial fails at Build the Program Pressing Ctrl+Shift+B gives the error:
Executing task: /usr/bin/g++ -g -o /mnt/f/dev/wslprojects/helloworld/helloworld.out helloworld.cpp < g++: The term 'g++' is not recognized as the name of a cmdlet, function, script file or operable program. Check the spelling […]
- /usr/bin/g++ -g -o /mnt/f/dev/wslprojects/helloworld/helloworld.out h ...
-
+ CategoryInfo : ObjectNotFound: (/usr/bin/g++:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Sanity check 1: g++ -g -o /mnt/f/dev/wslprojects/helloworld/helloworld.out helloworld.cpp does work from WSL Sanity check 2: g++ is indeed under /usr/bin in WSL
What can I do to make things work?
@CedricMi Sorry you ran into an issue. The commands under "Create a workspace" need to be run in a Windows command prompt on the Windows side, not in Ubuntu. I see that the example has been mis-formatted and says "```bash" which is incorrect. I'm going to fix that now and the fix should go live in a day or so.
The 'g++' not recognized issue should be because the integrated shell is by default PowerShell.exe not bash.exe. You may change the shell per task to bash.exe by following this: https://code.visualstudio.com/docs/editor/tasks#_can-a-task-use-a-different-shell-than-the-one-specified-for-the-integrated-terminal
Any of you tried the tutorial from start to finish ? I obtain so many different results, e.g. generated files are not the same, and so forth, many steps don't work.
The 'g++' not recognized issue should be because the integrated shell is by default PowerShell.exe not bash.exe. You may change the shell per task to bash.exe by following this: https://code.visualstudio.com/docs/editor/tasks#_can-a-task-use-a-different-shell-than-the-one-specified-for-the-integrated-terminal
So I changed task.json as follow:
{
"version": "2.0.0",
"windows": {
"options": {
"shell": {
"executable": "c:\\Windows\\sysnative\\bash.exe",
"args": [
]
}
}
},
"tasks": [
{
"label": "build hello world on WSL",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"/mnt/f/dev/projects/helloworld/helloworld.out",
"/mnt/f/dev/projects/helloworld/helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
It's not working: no helloworld.out in the directory and:
/bin/bash: g++ -g -o /mnt/f/dev/projects/helloworld/helloworld.out /mnt/f/dev/projects/helloworld/helloworld.cpp: No such file or directory
The terminal process terminated with exit code: 127
Although from wsl: g++ -g -o /mnt/f/dev/projects/helloworld/helloworld.out /mnt/f/dev/projects/helloworld/helloworld.cpp does work
@CedricMi you may need to provide args
"options": {
"shell": {
"executable": "c:\\Windows\\system32\\bash.exe",
"args": [
"-c"
]
}
}
@CedricMi did you ever get this working? We updated the document based on your feedback and that of others.
@mikeblome I'm almost there.
Note: In Set path to system headers
You should inform the reader he has to transform the path:
C:/Users/<my windows user name>/AppData/Local/ [...]
into
C:\\Users\\my windows user name>\\AppData\\Local\\ [...]
Helloworld does compile. I can debug as instructed in the tutorial.
However, why does the debugger not Step into
cout << word << " ";
?
@CedricMi I'll update the docs per your suggestion; you are correct that path needs to be transformed.
Also, I can repro that "Step into" does not seem to work on that line. The debugger seems to skip over it and return to the top of the loop. Can you report this to the team by going to Command Palette > Help: Report Issue? Since this is not a documentation issue, and you are able to complete the tutorial, I'm closing this issue. Feel free to reopen or create a new issue if you have further problems. We appreciate the feedback!