Skip to content
Advertisement

Using Windows Subsystem for Linux (WSL) from Sublime Text

I wanted to use gcc, g++ and make from Sublime Text to be able to compile C and C++ code to Linux runnables on Windows. I couldn’t run bash.exe from Sublime Text, as many other users on Stack Overflow.

Advertisement

Answer

  1. You have to copy the C:WindowsSystem32bash.exe file to the C:WindowsSysWOW64 directory. Required because of the WoW64 file system redirection (Thanks Martin!)

  2. Then you have to create a new build system in the Sublime Text with the following code. (Tools -> Build System -> New Build System...)

    {
      "cmd" : ["bash", "-c", "gcc ${file_name} -o ${file_base_name} && ./${file_base_name}"],
      "shell": true,
      "working_dir": "${file_path}",
    }

    This code will complile the .c code and than run it. The output will be shown in the Sublime’s Build Results panel.

  3. When you want to use this Build System, select it in the Tools -> Build System list, then hit Ctrl + B.

You can customize the command I put there, the main thing is that you can run Linux commands using bash -c "CommandsYouWantToRun"

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement