C语言 Sublime Text 2 C 编程语言的构建系统
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13670064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sublime text 2 build system for C programming language
提问by userzerox
I'm learning C language. I'm referring book by Dennis Ritchie & Kernighan. And there fore Just ANSI complaint programs. I've installed ANSI compiler. I just installed Sublime text 2 editor. Could someone give me a build system that would do the following.
我正在学习C语言。我指的是 Dennis Ritchie & Kernighan 的书。因此,只有 ANSI 投诉程序。我已经安装了 ANSI 编译器。我刚刚安装了 Sublime text 2 编辑器。有人可以给我一个可以执行以下操作的构建系统吗?
1) Compile my source file
1)编译我的源文件
2) Display error (in well formatted manner) within sublime on unsuccessful compilation.
2) 在编译失败时在 sublime 中显示错误(以格式良好的方式)。
3) On successful compilation, Generate binary file with name same as the Source file name within my working directory.
3) 编译成功后,在我的工作目录中生成名称与源文件名相同的二进制文件。
4) Accept Any user input within sublime to calculate Output. (Since i'm a beginner i mostly write programs that would ask the user to input. ex: Program to calculate number of characters in user input name.)
4) 接受 sublime 内的任何用户输入来计算输出。(由于我是初学者,我主要编写要求用户输入的程序。例如:计算用户输入名称中字符数的程序。)
5) Separate selection for Compile & run.
5) 单独选择编译和运行。
Thanks in Advance.
提前致谢。
回答by c633
From menu, choose Build -> New build system ... and copy-paste this:
从菜单中,选择 Build -> New build system ... 并复制粘贴:
Windows
视窗
Compile Only:
仅编译:
{
"cmd" : ["gcc", "$file_name", "-o", "${file_base_name}.exe", "-lm", "-Wall"],
"selector" : "source.c",
"shell":true,
"working_dir" : "$file_path"
}
Compile & Run:
编译运行:
{
"windows":
{
"cmd": ["cc","-std=c99" ,"$file_name","-o", "${file_base_name}.exe", "-lm", "-Wall", "&","start", "${file_base_name}.exe"]
},
"selector" : "source.c",
"shell": true,
"working_dir" : "$file_path",
}
Linux
Linux
Compile Only:
仅编译:
{
"cmd" : ["gcc", "$file_name", "-o", "${file_base_name}", "-lm", "-Wall"],
"selector" : "source.c",
"shell":false,
"working_dir" : "$file_path"
}
Compile & Run:
编译运行:
{
"linux":
{
"cmd": ["cc","-std=c99" ,"$file_name","-o", "${file_base_name}", "-lm", "-Wall", ";", "./${file_base_name}"]
},
"selector" : "source.c",
"shell": true,
"working_dir" : "$file_path",
}
and save this with extension *.sublime-build
并使用扩展名 *.sublime-build 保存它
ST just is a editor, so you cannot use it as a input stream, you have to use a shell like bash, zsh, ... to do it.
ST 只是一个编辑器,因此您不能将其用作输入流,您必须使用 bash、zsh 等 shell 来执行此操作。
回答by Dr. Astragalo
See the status bar down in sublime text 2 where it says the language or it says 'plain text',
click it and search for 'c' language. to build you just need to save Ctrl-sand Build Ctrl-B, Easy as cake!. also you could try a C friendly IDE like Eclipse. http://www.eclipse.org/
在 sublime text 2 中查看状态栏,其中显示语言或显示“纯文本”,单击它并搜索“c”语言。建造你只需要保存Ctrl-s和建造Ctrl-B,就像蛋糕一样简单!。你也可以尝试像 Eclipse 这样的 C 友好的 IDE。http://www.eclipse.org/

