从Sublime Text使用Windows子系统Linux(WSL)

时间:2016-11-06 23:18:31

标签: linux windows bash sublimetext windows-subsystem-for-linux

我想使用Sublime中的AL<filter class="solr.PorterStemFilterFactory"/>gcc,以便能够在Winows上将c和c ++代码编译为Linux runnables。我无法从Sublime运行g++,就像stackoverflow上的许多其他用户一样。

3 个答案:

答案 0 :(得分:6)

  1. 您必须将C:\Windows\System32\bash.exe文件复制到C:\Windows\SysWOW64\目录。 因WoW64 file system redirection(谢谢Martin!)

  2. 而必需
  3. 然后你必须使用以下代码在Sublime Text中创建一个新的构建系统。 (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}",
    }

    此代码将编译.c代码而不是运行它。输出将显示在Sublime的Build Results面板中。

  4. 如果您想使用此Build System,请在Tools -> Build System列表中选择它,然后点击Ctrl + B

  5. 您可以自定义我放在那里的命令,主要是您可以使用bash -c "CommandsYouWantToRun"

    运行Linux命令

答案 1 :(得分:1)

在我看来,在WSL2中,最好的方法是使用下面的sublime-build文件。

  • 您必须使用以下代码在Sublime Text中创建一个新的构建系统。
    segment .text global swap swap: mov al,[rdi+rsi] ; Move one byte from [rdi+rsi] to AL. AL is lower 8 bits of RAX mov cl,[rdi+rdx] ; Move one byte from [rdi+rdx] to CL. CL is lower 8 bits of RCX mov [rdi+rsi],cl ; Move the byte in CL to [rdi+rsi] mov [rdi+rdx],al ; Move the byte in AL to [rdi+rdx] mov rax,rdi ret
Tools -> Build System -> New Build System...
  • 此代码将编译.cpp代码,并分别使用inp.in和out.in作为输入和输出文件( { "shell_cmd": "ubuntu run \"g++ `wslpath '${file}'` && ./a.out<inp.in>out.in \" ", "shell":true, "working_dir":"$file_path", "selector":"$file_name" } )。输出将显示在Sublime的Build Results面板中。

  • 当您要使用此构建系统时,请在Optional, if you don't want that, then replace ./a.out<inp.in>out.in with ./a.out列表中选择它,然后单击Tools -> Build System

答案 2 :(得分:0)

在WSL 2上,建议的解决方案不起作用。这是在WSL 2目标上执行在Windows的Sublime Text中编辑的脚本的解决方案。创建一个bash-wsl.sublime-build文件:

{
    "shell_cmd": "bash -c \"wslpath '${file}'\" | bash -s",
    "shell": true,
}