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.