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

相关文章
相关标签/搜索