I want to compile a simple C program with GCC. What do I need to put in the sublime-build file to do so?
Mac OS X:
{
"cmd" : ["gcc", "$file_name", "-o", "${file_base_name}"],
"selector" : "source.c",
"shell":true,
"working_dir" : "$file_path"
}
Windows:
{
"cmd" : ["gcc", "$file_name", "-o", "${file_base_name}.exe"],
"selector" : "source.c",
"shell":true,
"working_dir" : "$file_path"
}
The accepted answer did not work for me.
What I did is the following:
{
"cmd" : ["make $file_base_name && ./$file_base_name"],
"selector" : "source.c",
"shell": true,
"working_dir" : "$file_path",
}
Setting shell
to true
means it reads the cmd
as one line, so I call make to compile and then run the script. The other option is to have shell
set to false
but you're unable to run multiple cmd
. So the only way I got it to work was have it make the file with CMD + B
and then run it with CMD + Shift + B
:
{
"cmd" : ["make", "$file_base_name"],
"selector" : "source.c",
"shell": false,
"working_dir" : "$file_path",
"variants": [
{
"cmd" : ["./$file_base_name"],
"name": "Run"
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With