Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to synchronize code files on windows with WSL/linux?

Basically I have some C/C++ code that I need to build and debug on a Linux machine. Unfortunately, my windows laptop doesn't have enough free hard space to install some Linux dist nor does it have enough free RAM to comfortably run VM.

Until now, I dealt with it rather comfortably using WSL, but the scale was rather small. It was easy to edit and debug 2-3 .c files through CLI and gdb, but it became really annoying on a large scale projects.

I want something simple as "edit code in windows IDE [X], compile it on remote Linux/WSL (the project uses Makefiles), and preferably debug it via gdb".

VS has something close to what I want, but it can't deal with existing Linux projects. It needs to create a new configuration which is alien to the project's Makefile.

like image 886
Dan M. Avatar asked Sep 27 '18 21:09

Dan M.


2 Answers

I know this question is a bit old, but I think the solution is to make a symlink between your WSL folder and the Window's folder. This is how I handled it for a Ubuntu-20.04 WSL:

  1. Access PowerShell in Administrator mode
  2. Type cmd.exe in the PowerShell
  3. Once cmd.exe is opened, type mklink /d C:\<path_to_your_Windows_folder> \\wsl$\Ubuntu-20.04\home\<your_user>\<path_to_your_WSL_folder>

EDIT This was tested under Windows 10 Version 2004 with WSL2

like image 178
Luan Rios Campos Avatar answered Sep 30 '22 18:09

Luan Rios Campos


I'm unsure about C and C++ but it sounds like this is exactly the same as how i work in node and javascript every day.

I checkout my code using git inside WSL to a location like /mnt/c/code/myproject. Then using sublime/VS code/webstorm i edit the files in windows in the location c:\code\myproject this works really well and have been doing this every day for over a year.

Things to be aware of are that you need to ensure that your editor of choice saves files with linux line endings and that all command line operations are done inside WSL.

Please see this article to see the differences between windows and linux files and how this works inside the WSL.

like image 41
Damo Avatar answered Sep 30 '22 17:09

Damo