Sublime Forum

Sublime for C/C++ development

#1

Hello Guys,

I am new to sublime editor. I have been using Geany/Gvim for my C/C++ development. Today I tried Sublime and found it to be very beautiful and have many features.
I want to use sublime editor as my development platform for my C/C++ projects. I want to compile and run single files. There is build option in the tools menu, but I am clueless about using it.

Can anyone guide me or give some document to use the Sublime editor as simple IDE for my C/C++ development.

Environment:
OS: Windows 7 64Bit
Compiler: gcc/g++
Location: C:\MinGW\bin
Sublime Ver: 2

Thanks
Abhijeet

0 Likes

#2

I would like some information on this as well.

0 Likes

#3

You should try sublimeclang and sublimegdb

0 Likes

#4

If you choose the Tools menu, Build System, New Build System you can create a file something like this:

{ "cmd": "javac", "$file"], "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.java" }
I copied this from the default ‘JavaC.sublime-build’ file. You can replace “javac” with (presumably) “gcc”. If the compiler is not in your environment paths then you’ll need to supply the full path to it - but you’ll need to escape the back-slashes “C:\something\else\gcc”

“$file” means “the current file”. You can probably delete the file_regex line. And your selector will be (presumably) “source.c”, “source.cpp” or “source.c++”. If the same compiler works for both c and c++ you can separate them with commas: “source.c, source.c++”.

Save this file in your Packages\C++ or \User folder with the extension ‘sublime-build’. You should probably restart ST2 and this new option should appear in the Build list. If you use it once then Ctrl-B will probably default to it in future.

I’m not sure about arguments; I assume you could bung them in with the $file: “-c -whatever $file”. Andy.

0 Likes

#5

[quote=“agibsonsw”]If you choose the Tools menu, Build System, New Build System you can create a file something like this:

{ "cmd": "javac", "$file"], "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.java" }
I copied this from the default ‘JavaC.sublime-build’ file. You can replace “javac” with (presumably) “gcc”. If the compiler is not in your environment paths then you’ll need to supply the full path to it - but you’ll need to escape the back-slashes “C:\something\else\gcc”

“$file” means “the current file”. You can probably delete the file_regex line. And your selector will be (presumably) “source.c”, “source.cpp” or “source.c++”. If the same compiler works for both c and c++ you can separate them with commas: “source.c, source.c++”.

Save this file in your Packages\C++ or \User folder with the extension ‘sublime-build’. You should probably restart ST2 and this new option should appear in the Build list. If you use it once then Ctrl-B will probably default to it in future.

I’m not sure about arguments; I assume you could bung them in with the $file: “-c -whatever $file”. Andy.[/quote]

Thanks agibsonsw for the info… What about running the newly build application from sublime editor?
Is there a way to map the errors in the build to the line numbers. I know this is not IDE but having that feature will greatly help in debugging applications.

-Abhijeet

0 Likes

#6

hi,im a newbie sublime and c++
in my university My teacher taught the old script using borland c + + 4 or 5, I had difficulty when using sublimetext, ranging from the script in borland c + + can running but in sublimetext cannot be running, and when I want to compile,i also struggled
need your help.thanks :laughing:

0 Likes

#7

To compile and run I’m using this ‘sublime-build’ file:
{
“cmd”: “mingw32-gcc”, “-Wall”, “-time”, “$file”, “-o”, “$file_base_name”, “&&”, “$file_base_name”],
“file_regex”: “^ ]File "(…?)”, line ([0-9]*)",
“working_dir”: “${project_path:${folder}}”,
“selector”: “source.c”,
“shell”: true
}

Do you have any idea how to use ST2 console for input (scanf, gets…)?

0 Likes

#8

[quote=“adn”]
Do you have any idea how to use ST2 console for input (scanf, gets…)?[/quote]

ST2 doesn’t support interactive build systems. Sorry.

0 Likes

#9

[quote=“C0D312”]
ST2 doesn’t support interactive build systems. Sorry.[/quote]

Thank you for your quick respond, nice day!

0 Likes

#10

To build and run with ST2 under Unix-like OS:

{
“cmd”: “g++ -Wall ${file} -o ${file_base_name} && ./${file_base_name}”],
“working_dir”: “${file_path}”,
“shell”: true
}

Nice coding!

0 Likes

#11

Thanks for:

[quote]{
“cmd”: “g++ -Wall ${file} -o ${file_base_name} && ./${file_base_name}”],
“working_dir”: “${file_path}”,
“shell”: true
}[/quote]

I’m using this ‘sublime-build’ file on windows 7, mingw:

{ "cmd": "g++ -Wall ${file} -o ${file_base_name} && ${file_base_name}"], "working_dir": "${file_path}", "shell": true, "encoding": "cp1251" }
But Incorrect encoding of Russian characters in output.

0 Likes