本文介绍如何在sublime3中新建一个build system,将sublime和Visual Studio的cl编译器链接,这样在sublime中按Ctrl+B就可以自动编译c++代码。
在sublim中选择Tool -> Build System -> New Build System,新建一个.sublime_build文件,将如下的内容复制进文件中。
{
"cmd": ["$packages\\User\\build.bat", "$file"],
"working_dir": "${file_path}",
"file_regex": "^(...*?)[(]([0-9]*),([0-9]*)[)]",
"shell": true,
"encoding": "gb2312",
"variants":
[
{
"name": "Run",
"cmd": ["$packages\\User\\build.bat", "$file", "&", "${file_path}/${file_base_name}.exe"]
}
]
}
@SET SRC_FILE="%1"
@SET PATH=D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin;%PATH%
@CALL vcvars32.bat
cl /O2 /GL /W3 /TP /EHsc %SRC_FILE%
这样设置完成之后,在sublime中按Ctrl+B就可以编译cpp文件,按Ctrl+Shift+B编译并且运行。
如果有更加深入的需求,可以通过修改bat文件的内容或是编写makefile文件来实现。
本文参考链接:https://gist.github.com/clijiac/2814517