Code and Run Apps with WSL2

Switching between VMs, dealing with the unfamiliarity feeling of the different OS and windowing system, and having your work-in-progress source code spread across multiple systems can become rather annoying and easily lead to a loss of motivation.

For quite some time, I’ve been trying to get the Scancode feature finalized for SFML and experienced the described issue multiple times. One solution that closes the gap between Linux and Windows is to use WSL2, VS Code’s Remote Development extension pack and an XServer running on Windows.

I won’t go much into detail, as it can become rather complex, but merely link a few resources that might be of interest to future me or others wanting to replicate the setup.

Install WSL2

  • Make sure you have Windows 10 version 2004 or higher
  • Install WSL2 with wsl --install in an administrator PowerShell oder CMD
  • Install all the tools you want or need, as you would on your Ubuntu VM

Code with Visual Studio Code in WSL2

Run X11 Apps on Windows with WSL2

Troubleshooting

Error: Can’t open display

Make sure the IP address is correct after the error message. If it’s not correct, then check the command that retrieves the host IP address in your .bashrc file.

Also when starting XLaunch don’t forget to check “Disable access control”, so the WSL2 can connect to the server. Note: Depending on the network your in, this might pose a small security risk.

See also this GitHub issue for some more tips.

ldconfig: libcuda.so.1 is not a symbolic link

Might be totally unrelated to everything described here, but I had that error message whenever ldconfig was executed. Basically, you need to the delete the copied files on the host system and create symbolic links in WSL2. See this GitHub issue for how to fix it.

Leave a Comment

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.