My question is what are the tools one needs in order to write programs in c++? |
You write C++ code in plain text files. These files are then fed to a compiler.
The compiler takes each file individually and the following things happen:
- Any lines of the form
#include <someFile>
have the file
someFile pasted into that spot.
- The compiler then starts at the top and compiles the text file into an object file. Any function calls to functions that are not defined in that single file have a note left to the linker asking it to find that function and link it properly.
The linker is then given a list of all the object files to link. If you are making an executable, one of these object files must contain the
main()function. If you are making a library, this is not necessary. The linker goes through each object file, ensuring that every function call is properly linked to the actual object code of that function. Some of these will be functions you wrote. Some will be functions in libraries you are using. Somewhere will be the function (provided by the writer of the linker/compiler and specific to your operating system and architecture) that sets things up and actually calls
main() when you run the executable; this set of cleverness is generally referred to as the runtime library (
http://en.wikipedia.org/wiki/Runtime_library ) and it handles the platform specific things for you so that you don't need to.
The linker gives back the executable or library.
So, to code some C++, you need:
A text editor.
A compiler.
A linker.
Commonly, the compiler and linker are provided together, and usually are wrapped into some convenient method of chaining them together so that you don't need to run them separately yourself. You can do, though, and even if you never do, knowing what they actually do will be a big help when you have to deal with your own programming errors (the number of times you see people trying to fix a
linker error by altering unrelated code going into the
compiler is depressing).
Your choice of compiler/linker is often related to your operating system and/or IDE of choice (note that an IDE is by no means necessary - text editor, compiler, linker is what's
needed).
The GCC (GNU Compiler Collection) is well-regarded. The young upstart LLVM (with clang front-end) has fantastic diagnostic messages. There are many more options.