How to run and compile .c on Sublime Text 2 [MAC OS X]

I'm studying C in college right now, and the teachers told me to use code blocks as an IDE, but in my opinion, code blocks are a bit ugly and so I chose Sublime Text 2, BEST IDE / Text Editor there.

At the moment, I write my code through sublime, save it, and then compile it through mac os terminal (gcc), and then run it on the terminal ...

What I want to know, if possible, is how to do it directly from the sublime, using its console or plug-in (or something else), in other words, I want to know if mine can be compiled. c and run it in just a few clicks right on the sublime ... (now I just create console applications)

I read some posts here about this topic, but none of them helped me solve this problem.

+6
source share
3 answers

The main assembly file for C might look like this:

{ "cmd" : ["/path/to/gcc", "$file_name", "-o", "${file_base_name}", "-lgsl", "-lgslcblas", "-lm" , "-Wall"], "selector" : "source.c", "shell":false, "working_dir" : "$file_path", "variants": [ { "name": "Run", "cmd": ["bash", "-c", "/path/to/gcc '${file}' -Wall -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"] } ] } 

To simply compile, press command + b .

To compile, press command + shift + b

The only thing you need to do is point the path to your gcc and enable the libraries you use (I left some GSL stuff for this example). $_variables are sublime assembly system variables and should not be changed. For more information about these variables, see here .

Here you can put the real assembly file:

 ~/Library/Application Support/Sublime Text 2/Packages/User/C.sublime-build 
+6
source

I used the following as .sublime-build to compile and run C. Mostly editing the code used for C ++. Worked for me.

 { "cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c", "variants": [ { "name": "Run", "cmd": ["bash", "-c", "gcc '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"] } ] } 
+3
source

If you use makefile , you can use something like this:

 { "cmd" : ["/usr/bin/make"], "selector" : "source.c", "shell":false, "working_dir" : "$file_path", "variants": [ { "name": "Run", "cmd": ["bash", "-c", "/usr/bin/make && '${file_path}/${file_base_name}'"] } ] } 
0
source

All Articles