解决方案
我们需要创建一个新的编译系统,具体步骤:SublimeText → Tools → Build System → New Build System
进入以后,清除原先内容,根据自己的系统将以下内容写入,保存文件到其给定位置(不要自己变更位置),命名为 MyCBuild.sublime-build。命名可以自定,但是后缀(.sublime-build)后面的不要更改!!!
Windows
{
"windows": {
"cmd": ["gcc", "-std=c11", "${file}", "-o", "${file_base_name}.exe"],
},
"cmd": ["gcc", "-std=c11", "${file}", "-o", "${file_base_name}"],
"file_regex": "^(.*)\\(([0-9]+),([0-9]+)\\) (Error|Fatal): (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"variants": [
{
"name": "Run",
"shell": true,
"windows": {
"shell_cmd" : "start cmd /c \"\"${file_base_name}.exe\" & echo. & pause\""
}
},
{
"name": "Build and Run",
"shell": true,
"windows": {
"shell_cmd": "gcc -std=c11 \"${file}\" -o \"${file_base_name}.exe\" && start cmd /c \"\"${file_base_name}.exe\" & echo. & pause\""
},
}
]
}
MacOS
{
"cmd": ["gcc", "-std=c11", "${file}", "-o", "${file_base_name}"],
"file_regex": "^(.*)\\(([0-9]+),([0-9]+)\\) (Error|Fatal): (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"osx": {
"path": "/usr/local/bin:/usr/bin:/bin:${path}",
"cmd": ["clang", "-std=c11", "${file}", "-o", "${file_base_name}"],
},
"variants": [
{
"name": "Run",
"shell": true,
"osx": {
"shell_cmd": "echo 'cd \"${file_path}/\"' > '/tmp/${file_base_name}' && echo './\"${file_base_name}\"' >> '/tmp/${file_base_name}' && echo read >> '/tmp/${file_base_name}' && chmod +x '/tmp/${file_base_name}' && open -a Terminal.app '/tmp/${file_base_name}'"
},
},
{
"name": "Build and Run",
"shell": true,
"osx": {
"shell_cmd": "clang -std=c11 '${file}' -o '${file_base_name}' && echo 'cd \"${file_path}/\"' > '/tmp/${file_base_name}' && echo './\"${file_base_name}\"' >> '/tmp/${file_base_name}' && echo read >> '/tmp/${file_base_name}' && chmod +x '/tmp/${file_base_name}' && open -a Terminal.app '/tmp/${file_base_name}'"
},
}
]
}
Linux系统
{
"cmd": ["gcc", "-std=c11", "${file}", "-o", "${file_base_name}"],
"file_regex": "^(.*)\\(([0-9]+),([0-9]+)\\) (Error|Fatal): (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"variants": [
{
"name": "Run",
"shell": true,
"linux": {
"cmd": ["gnome-terminal -- bash -c \"\\\"./${file_base_name}\\\";echo;read line;exit; exec bash\""]
},
},
{
"name": "Build and Run",
"shell": true,
"linux": {
"cmd": ["gcc -std=c11 \"${file}\" -o \"${file_base_name}\" && gnome-terminal -- bash -c \"\\\"./${file_base_name}\\\";echo;read line;exit; exec bash\""]
},
}
]
}
运行测试
接着我们在编译前,Tools → Build System → 勾选MyCBuild,使用 Ctrl+B 选择 Build and Run 便可以正常出结果了。