1、下载安装Sublime text2 for windows
下载地址:http://www.sublimetext.com/
2、下载安装 MinGW
我们使用的编译器是g++,所以需要下载安装MinGW(下载地址:http://sourceforge.net/projects/mingw/),
下载MinGW
后运行
点击All Packages=>MinGW Base System
勾选mingw32-base
mingw32-gcc-g++
如果少了某些包,下次运行程序时可以再增加的,
然后点击左上角的Installation=>Apply changes=>Apply开始下载
3、设置系统变量
下载完后配置环境变量(Win7)
计算机=>属性->高级->环境变量
在系统变量"Path"后面加入MinGW\bin的具体路径,
重启电脑后,在cmd中执行g++ -v
4、配置Sublime text编译命令
Sublime Text 2=>Tools => Build System => New Build System
将代码(下面两种代码都可行)拷贝并保存为xxx,sublime text默认会给你加个sublime-build后缀,即xxx.sublime-build,
关闭sublime text,再次启动sublime text并进入Tools => Build System选择xxx,
然后执行ctrl+b生成对应exe文件,
ctrl+shift+b执行exe文件,
代码1
{
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"encoding": "cp936",
"shell": true,
"variants":
[
{
"name": "Run",
//"cmd": ["CMD", "/U", "/C", "g++ ${file} -o ${file_base_name} && ${file_base_name}"]
"cmd": [ "start", "${file_path}/${file_base_name}.exe"]
}
]
}
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"encoding": "cp936",
"shell": true,
"variants":
[
{
"name": "Run",
//"cmd": ["CMD", "/U", "/C", "g++ ${file} -o ${file_base_name} && ${file_base_name}"]
"cmd": [ "start", "${file_path}/${file_base_name}.exe"]
}
]
}
参考网址:http://blog.sina.com.cn/s/blog_6e7384df0101qzya.html
ctrl+b能够编译出 文件名.exe,
但是按ctrl+shift+b无法运行编译出的exe
解决方法
将
"cmd": [ "start", "${file_path}/${file_base_name}.exe"]
修改为
"cmd": [ "start","C:/cb_console_runner.exe","${file_path}/${file_base_name}.exe"]
其中cb_console_runner.exe可以通过
http://download.csdn.net/detail/zxquietc/7768857
网址下载并放到C:/目录下
代码2
{
"cmd": ["mingw32-g++.exe", "-o", "$file_base_name", "$file"],
"variants": [
{
"cmd": ["start", "cmd", "/k", "$file_base_name"],
"shell": true,
"name": "Run"
}
]
}
参考网址:http://www.sublimetext.com/forum/viewtopic.php?f=3&t=14822
其中mingw32-g++.exe可以改为g++,
这要看你下载MinGW时选择下载了哪些东西,然后看MinGW\bin下是否有g++或者mingw32-g++