Windows系统下 Sublime Text 3配置 G++开发环境

  1. 先安装Sublime Text3minGW-w64 ,并在PATH环境变量中加入minGW-w64bin目录,比如我机器上的目录是"D:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin"
  2. Sublime Text 3点击Tools,Build System,New Build System,

  3. 将这个文件拷贝进去,保存到用户的AppData的相应目录下,比如我的是"C:\Users\ericxie\AppData\Roaming\Sublime Text 3\Packages\User",文件名为g++.sublime-build

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"working_dir": "${file_path}",
"cmd": ["g++", "${file}", "-o", "${file_base_name}.exe", "-lm", "-Wall", "-O2","-std=gnu++11","-Wl,--stack,100000000"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"selector": "source.c",
"shell": true,
"variants":
[
{
"name": "Run",
"shell":true,
"cmd": ["start","/D ${file_path}","run1.bat","${file_base_name}.exe"]
},
{
"name": "Output",
"cmd": ["start","/D ${file_path}","run.bat","${file_base_name}.exe","std.in","std.out"]
},
{
"name": "Diff",
"cmd": ["start","/D ${file_path}","run.bat","${file_base_name}.exe","std.in","std.diff"]
}
]
}
  1. minGWbin目录下建立两个文件,run.bat,run1.bat。内容如下:

run.bat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@echo off
if "%time:~0,2%" lss "10" (SET HOUR=%time:~1,1%) else (SET HOUR=%time:~0,2%)
if "%time:~3,2%" lss "10" (SET MINUTE=%time:~4,1%) else (SET MINUTE=%time:~3,2%)
if "%time:~6,2%" lss "10" (SET SECOND=%time:~7,1%) else (SET SECOND=%time:~6,2%)
if "%time:~9,2%" lss "10" (SET MILLISECIOND=%time:~10,1%) else (SET MILLISECIOND=%time:~9,2%)
set /a START=%HOUR%*3600*100+%MINUTE%*60*100+%SECOND%*100+%MILLISECIOND%
%1 <%2 >%3
if "%time:~0,2%" lss "10" (SET HOUR=%time:~1,1%) else (SET HOUR=%time:~0,2%)
if "%time:~3,2%" lss "10" (SET MINUTE=%time:~4,1%) else (SET MINUTE=%time:~3,2%)
if "%time:~6,2%" lss "10" (SET SECOND=%time:~7,1%) else (SET SECOND=%time:~6,2%)
if "%time:~9,2%" lss "10" (SET MILLISECIOND=%time:~10,1%) else (SET MILLISECIOND=%time:~9,2%)
set /a END=%HOUR%*3600*100+%MINUTE%*60*100+%SECOND%*100+%MILLISECIOND%
set /a TOTAL=(%END%-%START%)*10
echo.
echo Run time : %TOTAL% ms

run1.bat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@echo off
if "%time:~0,2%" lss "10" (SET HOUR=%time:~1,1%) else (SET HOUR=%time:~0,2%)
if "%time:~3,2%" lss "10" (SET MINUTE=%time:~4,1%) else (SET MINUTE=%time:~3,2%)
if "%time:~6,2%" lss "10" (SET SECOND=%time:~7,1%) else (SET SECOND=%time:~6,2%)
if "%time:~9,2%" lss "10" (SET MILLISECIOND=%time:~10,1%) else (SET MILLISECIOND=%time:~9,2%)
set /a START=%HOUR%*3600*100+%MINUTE%*60*100+%SECOND%*100+%MILLISECIOND%
%1
if "%time:~0,2%" lss "10" (SET HOUR=%time:~1,1%) else (SET HOUR=%time:~0,2%)
if "%time:~3,2%" lss "10" (SET MINUTE=%time:~4,1%) else (SET MINUTE=%time:~3,2%)
if "%time:~6,2%" lss "10" (SET SECOND=%time:~7,1%) else (SET SECOND=%time:~6,2%)
if "%time:~9,2%" lss "10" (SET MILLISECIOND=%time:~10,1%) else (SET MILLISECIOND=%time:~9,2%)
set /a END=%HOUR%*3600*100+%MINUTE%*60*100+%SECOND%*100+%MILLISECIOND%
set /a TOTAL=(%END%-%START%)*10
echo.
echo Run time : %TOTAL% ms
坚持原创技术分享,您的支持将鼓励我继续创作!