Sublime Forum

Set Up Compiler for C for Sublime Text 3

#3

Thank you for your quick response and your effort!
If I try to compile the main.c file I get the following error:

Sorry for my lack of knowledge and the inconvenience.

0 Likes

#4

Can you show the sublime project file?

0 Likes

#5

0 Likes

#6

Works for me. Are you using Sublime Text 2 or something?

0 Likes

#7

I am using Sublime Text 3. Perhaps I should switch to Sublime Text 2?

0 Likes

#8

No, definitely not :smiley: I’m not sure what the problem is. Your project file doesn’t seem to be highlighted correctly.

0 Likes

#9

I created a folder test. Opened a new file, copied your code into it and saved it in the folder as my project.sublime-project.

After that I created main.c. Coded HelloWorld and saved it.

When I went to Tools -> Build System I couldn’t find “mybuild”. So I moved on to Tools -> Build System > New Build System and created a “mybuild.sublime-build”. Now it shows “mybuild” at Tools -> Build System.
When I select the build system and press Build I get the error as shown in the previous pics.

0 Likes

#10

Right. But also open the sublime project file with Sublime. This is confusing, I know. You have to be in “project mode”, right now you are in “folder” mode. Go to Project -> Open Project and select the project file.

0 Likes

#11

Thank you! It seems to work now. But when I try to compile my “HelloWorld” the Console just shows: “[Finished in 0.2s]”.

No “HelloWorld” though.

0 Likes

#12

Thank you for your patience!!

0 Likes

#13

myproject.sublime-project is still not highlighted as seen in your picture either.

0 Likes

#14

0 Likes

#15

The build rule is just a compilation rule. So it compiles main.c into “myapp”.

To actually run your program called “myapp”, open the Terminal app, then do

$ cd Desktop
$ cd test
$ ./myapp

You could write a build system rule for that too:

	"build_systems":
	[
		{
			"file_regex": "(.+[^:]):(\\d+):(\\d+): (?:fatal )?((?:error|warning): .+)$",
			"name": "mybuild",
			"shell_cmd": "gcc -Wall -O2 main.c -o myapp",
			"working_dir": "${project_path}"
		},
                {
                        "name": "run the executable",
                        "shell_cmd": "./myapp",
                        "working_dir": "${project_path}"
                }
	],
1 Like

#16

Great. It works!! Thank you so much for your time!!

2 Likes

#17

Is there any way to output a information that looks like this:

"Process terminated with status 0 (0 minute(s), 1 second(s))
 0 error(s), 0 warning(s) (0 minute(s), 1 second(s))"
0 Likes

#18

i still face that problem please help me

0 Likes

#19

I want to learn C++ but I can’t understand from where I should start

0 Likes

#20

Try this new build system that I build for myself, It helped me to compile and execute c programs at the same time. Basically what the code does is it compiles the c program with the GCC compiler and opens the compiled c program in a new terminal.

[+] NOTE: “Works only on Linux distributions” …

[STEPS]

  1. Install xterm if you don’t have xterm installed on your Linux system. To install xterm use

    sudo apt-get install xterm

  2. Go to Tools > Build System > New build system

  3. Now enter this code

  1. Save it as GCCbuildsys.sublime-build

  2. Restart your sublime text 3 by closing it and reopening it again.

  3. Select the build system by going to

    Tools > Build System > GCCbuildsys

7.Now to compile and execute your program open up your c program and press Ctrl + b .

Hope it helps … :slight_smile:

1 Like

#21

Here is a screenshot of how it works

0 Likes

#22

Thanks, this really helped a lot. Works perfectly.

Thank you.

0 Likes