Sublime Forum

C++ Build System?

#1

Hi, (First Post)

I’ve been using ST2 for a while now and its a wonderful text editor.

I’ve just started learning C++ and I’ve tried out a few build systems but everytime the console just turns up an error of:

[Error 2] The system cannot find the file specified [Finished]

What am I doing wrong? Is my Build System setup wrong?

If it helps, I am using the GNU GCC Compiler.

Thanks!

0 Likes

#2

Hi, I actually wanted to compile some C from sublime text 2 today but find out there wasn’t build system for that. I’ve read documentation a bit and came up with this:

{
"cmd" : "gcc", "$file_name", "-o", "${file_base_name}.exe"],
"selector" : "source.c",
"working_dir" : "$file_path"
}

It should compile C as well as C++ code. It works well but I couldn’t get it to execute the program after it’s finished which is actually what I was hoping to achieve. If anyone knows how to run program after it was compiled, I’d be very grateful. I’ve tried this:

{
"cmd" : "gcc", "$file_name", "-o", "${file_base_name}.exe && ${file_base_name}.exe"],
"selector" : "source.c",
"working_dir" : "$file_path"
}

But it doesn’t work. I just get exe file named “test.exe && test.exe”. Probably because sublime feeds array fields as arguments for the gcc instead of just creating a string and executing it in cmd.

Note: you don’t need “.exe” if you’re on unix system.

0 Likes

#3

Ok, So I’ve figured out how to do build and run:

{
"cmd" : "gcc", "$file_name", "-o", "${file_base_name}.exe", "&&", "${file_base_name}.exe"],
"selector" : "source.c",
"shell":true,
"working_dir" : "$file_path"
}

I guess I’ve made a mistake in syntax earlier so I thought it doesn’t work.

0 Likes

#4

Hi,

Thanks for that Build System, I just keep on getting this now, even though I though I’d installed GCC correctly:

'gcc' is not recognized as an internal or external command, operable program or batch file. [Finished]

Sorry to bother you with another question, but you wouldn’t have any idea what’s going on here would you?

0 Likes

#5

Ok, after getting that to work I now have denied access…to compile in g++?

Seriously?

Also, none of my C++ programs accept C syntax and throw errors whenever I compile via Cygwin…

0 Likes

#6

So it looks like you’ve gotten the PATH issue figured out. Is there a permissions issue with where you’re storing your source?

0 Likes

#7

No I can store the files where-ever I want. I’m storing the files in the Cygwin home directory so I guess It’s a compiling permission issue. However, I can compile manually when typing in the Cygwin console. This is really confusing…

So I can compile in the Cygwin console itself but not through ST2…

0 Likes

#8

I was wondering how to get a c++ program to run as well, but I think our compilers are different. What should I change if I’m using Cygwin?

0 Likes