Part of your command is this:
"${file_path}/${file_base_name}", "<", "${file_path}/${file_base_name}.txt"
So if your cpp file is called foo.cpp, then it will evaluate to this:
"/your/path/foo.cpp < /your/path/foo.txt"
So I assume it can’t find foo.txt if it doesn’t exist.
I will be over-simplifying it, but the reason I mention CMake and Make is because Sublime Text is of course just a Text Editor, not an IDE.
As such, it doesn’t do any of the work for you that an IDE like CodeBlocks or Visual Studio does for you in the background.
For example, the default Sublime C++ build system (and the system you posted above) only builds the file you currently have open.
As you have probably guessed, when building from the command line you need to provide the g++ command with a list of all of the files you want to compile in a project, or compile them separately and manually link the resulting .o files.
This is fine if your project fits in one, or even a few files since it’s easy to write out something like:
g++ foo.cpp bar.cpp -o foobar
But once your project grows and is made up of dozens or even hundreds of files, keeping track of what you need to recompile and link together etc can quickly become unmaintainable.
This is where Make comes in.
Make is a utility which automatically determines which files in a program need to be recompiled and then recompiles them.
You can use Make on Windows by searching Google for “Make for Windows” and downloading it.
Once installed, you can write a Makefile for your project which describes the files to be used to build the final executable file.
When you run make it will look determine the files to be recompiled, recompile them and output the final program for you.
Since make is a command line utility you can easily use it in a Sublime build system.
So, instead of using g++ in your build system, you use make instead.
This will allow you to maintain larger projects easier, but makefiles can also become difficult to maintain after a while and learning how to write them properly can be a bit of a confusing task.
This is where CMake comes in.
CMake is yet another utility which generates build systems (for example, you can set it up to generate the Makefiles for you).
To use CMake you need to download it (just search for it on Google again), and once you have installed it you can use it from the command line or via a GUI they provide if you need it.
The nice thing about CMake is that it can generate more than just Makefiles.
It can generate many more build systems, you just have to specify which one you want.
So, like the make utility, CMake can be run from the command line, so you can set up a Sublime build system to run CMake.
CMake basically looks for files within your project named CMakeLists.txt.
These CMakeLists.txt files contain instructions written by you to tell it which files to include in the building of your project.
So basically, you set up a Sublime Text build system to have:
- A variant for running CMake on your project (generates the Make build system)
- A variant for running Make on your project (compiles your code and creates an executable)
- A variant to run the final compiled program
These three steps can be set up twice with different key bindings to work on debug and release builds.
You can find tutorials online about Make and CMake, and once you know how to use them it’s quite easy to set it all up in Sublime.
But you only really need to learn about CMake since CMake will generate the Makefiles for you.
I don’t have any links that specify how to set all of this up in a Sublime Text build system.
The only things I have found on Google are about how to build one file, just like the Sublime default C++ build system does.
Maybe I will write up how I set my projects up if it would help, but I don’t know when I will get around to it.
If I get to do it in the next few days I’ll post a link here.
Anyway, it can be a bit of work to set up large projects in Sublime properly, but once you get it working the first time any project after that will use the same build system and folder structure etc.
So if you have the patience it’s worth putting in the time to be able to use Sublime for C++ projects.