Sublime Forum

Help compiling and running C code

#1

how can i compile my code in C language in sublime text 2 ? I am new to this editor ,please help !

0 Likes

#2

is compiling and executing possible with sublime ?

0 Likes

#3

You need a build file (.sublime-build) that will appear under the Tools menu, Build System. You can copy and modify an existing one, or do a search for a C-version. This is my C++ version (I think it’s based on the default?).

[code]{
“cmd”: “g++”, “${file}”, “-o”, “${file_path}/${file_base_name}”],
“file_regex”: “^(…^:]):([0-9]+):?([0-9]+)?:? (.)$”,
“working_dir”: “${file_path}”,
“selector”: “source.c, source.c++”,

"variants":

	{
		"name": "Run",
        "cmd": "${file_base_name}.exe"]
		//"cmd": "bash", "-c", 
        //"g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
	}
]

}[/code]
Alternatively, there may be a C-Package that you can install.

0 Likes

#4

Is there any explanation to each of this entries ? I mean, I know what a working_dir is. But I don’t know what is a file_regex, selector & variants. Can anybody explain please ?

0 Likes

#5

The keys and what they do are in the build system section of the documentation.

I also have a video series that explains things in more detail.

0 Likes