brew install gcc
安裝過程大概5分鐘的樣子。c++
使用命令判斷是否安裝成功。git
$ gcc -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) Target: x86_64-apple-darwin14.1.1 Thread model: posix
打開Tools->Build System->New Build System,在新建的文件中輸入如下內容:github
{ "cmd" : ["gcc -o ${file_base_name} $file_name"], "shell" : true, "working_dir" : "$file_path", "selector": "source.c", "encoding":"utf-8", "variants" : [{ "name" : "Run", "cmd" : "./${file_base_name}" }] }
編輯完成後,保存文件,命名爲C.sublime-build,而後就能夠在Tools->Build System中選中這個編譯方式了,我的通常自動選中 Automaticshell
#include <stdio.h> int main(){ printf("hello world\n"); return 0; }
使用control+B進行編譯文件,使用control+shift+B運行編譯好的文件app
效果以下:svn
參kao文章ui
http://wenzhiquan.github.io/blog/2015/05/04/mac_os_yosemite_sublime_and_c/spa