Mac 下配置C編譯環境

第一步,相信你們的電腦上都安裝了subline,木有安裝的本身能夠去官網下載安裝

第二步,須要你的mac安裝gcc,已安裝的請跳過

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

 

第三步,配置subline text的c編譯系統

打開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

第四步,編輯hello.c文件

#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

相關文章
相關標籤/搜索