Your sublime text 3 IDE is confusing and spoiling you and you misconfigured it.
I hope that you are using some POSIX operating system, e.g. Linux.
Learn first to compile on the command line (in some terminal, outside of your editor or IDE). You absolutely need to understand how to invoke the GCC compiler (with commands in a terminal). Here are a few hints.
Be sure to have a recent GCC compiler, at least GCC 6 if you want C++11 or better. Perhaps you need to upgrade your compiler.
compiling a simple single-source program
To compile a single-source C++ program in single.cc
into tinyprog
executable, use
g++ -std=c++11 -Wall -g single.cc -o tinyprog
FYI, -std=c++11
sets your C++ standard, -Wall
ask for almost all warnings (and you might even add -Wextra
to get more of them), -g
is for debug information (in DWARF) and -o tinyprog
sets the output executable. Do ls -l tinyprog
, ldd tinyprog
, file tinyprog
to understand more about your executable.
compiling a simple multi-source program
To compile a small multi-source C++ program, e.g. made of first.cc
and second.cc
into a smallprog
executable
compile each of these into object files
g++ -std=c++11 -Wall -g -c first.cc -o first.o
g++ -std=c++11 -Wall -g -c second.cc -o second.o
link these object files into your executable
g++ -std=c++11 -Wall -g first.o second.o -o smallprog
building more complex programs
If you are using extra libraries, you may need to add some extra -I
includedir option at compile time, and some extra -L
libdir and -l
libname options at link time. You might want to use pkg-config to help you. You could, if curious, add -v
after g++
to be shown the actual steps done by g++
I run g++ --print-multi-lib
This just queries how your g++
compiler has been configured. You could also try g++ -v
alone.
Once you are able to compile by (one or several) commands, consider using some build automation tool. To build a single program using GNU make
, you could take inspiration from this.
Once you are fluent with compiling thru commands (either directly or thru some build automation tool like make
or ninja
or thru your script), read the documentation of your editor or IDE to configure it suitably.