软件准备:
sublime text 3
安装 & 配置 MinGW:
path变量添加一条 C:\MinGW\bin
注意,这里配置之后需要重启生效,但有办法可以强制生效:
set path=C:/MinGW/bin;%PATH%;
验证变量设置成功与否:
mingw-get //如果出现MinGW界面则设置成功
安装g++
mingw-get install gcc g++
验证g++安装成功与否:
g++ -v //打印出g++版本信息,说明安装成功
配置Sublime text 3
打开Tools->Build System->New Build System,键入如下信息:
{
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/c", "g++", "${file}", "-o", "${file_path}/${file_base_name}", "&&", "cmd", "/c", "${file_path}/${file_base_name}"]
},
{
"name": "RunInCommand",
"cmd": ["cmd", "/c", "g++", "${file}", "-o", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} & pause"]
}
]
}
Ctrl+S之后会提示保存,请保证文件名的格式为 “XXX.sublime-build”
XXX表示随意,我改成了“c++.sublime-build”
这一步完成之后,在Build System里面选中你刚刚保存的方案,即c++
随后在,Preferences->Key Bindings - User,可填入如下方案:
{ "keys": ["ctrl+alt+B"], "command": "build", "args": {"variant": "RunInCommand"} }
这里你可以自由修改运行的快捷键。
使用注意
C/C++的源文件必须在全英文的目录下运行!
END