Tip #1 : Customize Sublime

Learn how to customize sublime build system to compile multi-file cpp project in this 2 min blog.

Hey there ! It’s been a while since I posted something. I was trying to setup Sublime editor for my work at home. Thought I will share this tip that may be useful to you guys. Sublime comes with a single file compile option for C plus plus. This could be set as default build system using option : Tools->Build System-> C++ Single File. More info on Sublime Build Systems available here

However, I wanted to setup Sublime to compile multiple Cpp files in the given folder. So, all I did was to define a custom build option :

  • Tools-> Build System- > New Build System
  • Put the commands below into a new file:

{
“cmd”: [“g++”, “${file_path}/*.cpp”, “-o”, “$file_base_name”],
“working_dir”: “$folder”,
“selector”: “source.c++”,
“shell”: true,
“variants”:
[
{
“name”: “Run”,
“cmd”: [“g++”, “${file_path}/*.cpp”, “-o”, “$file_base_name”, “&&”, “$file_path/$file_base_name”],
“working_dir”: “$folder”,
“selector”: “source.c++”,
“shell”: true
}
]
}

  • Save the file as custom.sublime-build (can be custom or any name you want)
  • Set this as the default build system under
    • Tools->Build System->custom

Once you have your multiple cpp files in your workspace folder, use :

  • Ctrl+B to compile and
  • Ctrl+shift+B to run

Do you guys know how we could modify this to compile multi folder projects? Write to me at decodergirlblog@gmail.com.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: