What are the differences between C++ Toolchains and Compilers?

Viewed 2846

I know there are many compilers like gcc, clang, ninja but I keep hearing about "Toolchains" and so on but I don't understand what they are, like "gnu-toolchain' etc

3 Answers

There are several important terms:

  1. Compiler: the tool that transforms your code into compiled binary format. This usually includes an assembler step which is strictly speaking not really the compiler. Additionally, the tools you invoke are often "drivers" for the compiler/assembler/linker backend and you call them for every step in the build process (including linking). Examples are gcc/g++, clang/clang++, cl, icc/icpc, ...

  2. Assembler: assembles binary code generated by the compiler into a specific object file format (.obj files for Visual Studio, .o files for pretty much everything else). This is often built-in or at least invoked by the compiler when generating object files from source code. E.g. as, ...

  3. Linker: links together object files into an executable file format. This can be either a shared library (.dll/.dylib/.so) or an executable application (.exe). Examples are ld, link, lld, ...

    (3a) "Librarian": the Unix tool ar or the Visual studio tool lib.exe. This just bundles together object files into a thin wrapper format (.a/.lib).

  4. Debugger: tool used to inspect the values of variables defined in the source code at runtime. Examples are gdb, lldb, windbg, ...

  5. Toolchain: All of the above combined together. Debugger may or may not be considered a part of this though.

  6. Build tool: Tool that calls toolchain tools to transform a collection of source files into one or more libraries and executables. E.g. make, ninja, msbuild, xcode-build, ...

  7. Project generator: Takes an "abstract" description of a project and how the source files relate to the output files and generates something a build tool and/or IDE can use as if the project was built up inside that IDE. This makes cross-platform development a lot less painful if done right. Examples are cmake, qmake, premake, ...

  8. IDE: Text editor enhanced with varying levels of language annotation, code navigation, and toolchain integration. Often you can load project files, search for symbols, build, debug, etc. all from one IDE. Examples are Visual Studio, Qt Creator, KDevelop, Xcode, Eclipse, Code::Blocks, ... and with proper array of plugins: Vim, Emacs, VSCode, Atom, Sublime Text, ...

A toolchain is a set of tools (such as a compiler, linker, and assembler) intended to build your project. Additional tools, such as a debugger, can be associated with a toolchain. There can be several toolchains available, depending on the compilers installed on your system.

I know there are many compilers like gcc, clang, ninja

ninja is not a compiler. It is a build automation tool, or a "build system". A build automation tool reads a configuration, and generates necessary commands to call the tools of the toolchain necessary to build the program.

So for example CMake is what?

CMake is a configuration language and a program that generates a configuration for a build automation tool (such as ninja).

The reason to use such generator is that you have the option to use any build system (supported by the generator), which is important because not all systems support all build systems. Another reason for build system generator is detection of the capabilities of the system and the used toolchain, and using that information to change the configuration.

What are the differences between C++ Toolchains and Compilers?

Toolchain is a set of tools needed to translate your source files into an executable file (or a library) and execute it.

Compiler is one of the tools that the toolchain contains. The job of the compiler is to take a source file as an argument, and produce assembly code for the target system - although this view is becoming a bit obsolete: With link time optimisation, compiler instead produces "intermediate representation" language.

like "gnu-toolchain'

A GNU toolchain is a set of tools that uses the GNU compiler i.e. GCC.

So what does the Toolchain containt?

It can depend on context, but following is typical:

Translation phase:

  • compiler
  • assembler
  • linker

Execution phase:

  • dynamic loader
  • debugger
  • profiler

Other tools may also be considered to be part of the tool chain such as:

  • build automation tools
  • standard library
  • macro processors
  • archivers
  • package managers

And many other small tools that a programmer can use.

Related