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

Impossible to create project with WSL

Open CedricMi opened this issue 7 years ago • 7 comments

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

  1. 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 avatar Apr 10 '19 08:04 CedricMi

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

mikeblome avatar Apr 12 '19 17:04 mikeblome

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

zxbuaa avatar Apr 16 '19 06:04 zxbuaa

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 avatar Apr 18 '19 10:04 CedricMi

@CedricMi you may need to provide args

        "options": {
            "shell": {
                "executable": "c:\\Windows\\system32\\bash.exe",
                "args": [
                    "-c"
                ]
            }
        }

zxbuaa avatar Apr 19 '19 16:04 zxbuaa

@CedricMi did you ever get this working? We updated the document based on your feedback and that of others.

mikeblome avatar Apr 24 '19 20:04 mikeblome

@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 avatar Apr 25 '19 11:04 CedricMi

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

mikeblome avatar May 02 '19 21:05 mikeblome