Home Download Buy Blog Forum Support

Sublime for C/C++ development.

Sublime for C/C++ development.

Postby abhijeetnayak on Sun Feb 12, 2012 6:19 am

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
abhijeetnayak
 
Posts: 2
Joined: Sun Feb 12, 2012 6:12 am

Re: Sublime for C/C++ development.

Postby JesseMeyer on Sun Feb 12, 2012 10:22 am

I would like some information on this as well.
JesseMeyer
 
Posts: 4
Joined: Thu Feb 09, 2012 10:55 pm

Re: Sublime for C/C++ development.

Postby GMath on Sun Feb 12, 2012 3:54 pm

You should try sublimeclang and sublimegdb
GMath
 
Posts: 13
Joined: Tue Dec 06, 2011 9:27 pm

Re: Sublime for C/C++ development.

Postby agibsonsw on Mon Feb 13, 2012 3:24 am

If you choose the Tools menu, Build System, New Build System you can create a file something like this:
Code: Select all
{
   "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.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Sublime for C/C++ development.

Postby abhijeetnayak on Tue Feb 14, 2012 6:14 pm

agibsonsw wrote:If you choose the Tools menu, Build System, New Build System you can create a file something like this:
Code: Select all
{
   "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.


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
abhijeetnayak
 
Posts: 2
Joined: Sun Feb 12, 2012 6:12 am

Re: Sublime for C/C++ development.

Postby ahbsa on Mon Feb 27, 2012 1:17 pm

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 :lol:
ahbsa
 
Posts: 1
Joined: Mon Feb 27, 2012 12:57 pm

Re: Sublime for C/C++ development.

Postby adn on Tue Mar 06, 2012 12:18 am

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...)?
adn
 
Posts: 5
Joined: Mon Mar 05, 2012 8:35 pm

Re: Sublime for C/C++ development.

Postby C0D312 on Tue Mar 06, 2012 12:29 am

adn wrote:Do you have any idea how to use ST2 console for input (scanf, gets...)?

ST2 doesn't support interactive build systems. Sorry.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Sublime for C/C++ development.

Postby adn on Tue Mar 06, 2012 1:23 am

C0D312 wrote:ST2 doesn't support interactive build systems. Sorry.


Thank you for your quick respond, nice day!
adn
 
Posts: 5
Joined: Mon Mar 05, 2012 8:35 pm

Sublime for C/C++ development.

Postby adn on Sat Mar 17, 2012 10:36 pm

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!
adn
 
Posts: 5
Joined: Mon Mar 05, 2012 8:35 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: Nova, Orlmente and 38 guests