Questions tagged [compilation]

Compilation is the transformation of source text into some other form or representation. The most common usage of this tag is for questions concerning transformation of a programming language into machine code. This tag is normally used with another tag indicating the type of the source text such as a programming language tag (C, C++, Go, etc.) and a tag indicating the tool or compiler being used for the transformation (gcc, Visual Studio, etc.).

Compilation is the transformation of source text into some other form or representation. The software tool used is called a compiler. Most compilers process the source text to generate some sort of machine code for a target hardware machine. Some compilers generate the "machine code" for a target virtual machine (e.g. bytecode for a Java Virtual Machine).

In all of these cases the compiler creates new files of the transformed source text and these new files are used in some other processing step up to and including executing directly on hardware or virtual hardware.

Interpretation is the processing of source text by a software tool called an interpreter. Interpreters immediately execute the sense of the source text without generating a new, externally visible form of the source text. Compilers generate a new, externally visible form of the source text which is then executed by some other device whether actual hardware or virtual machine.

The lines between interpreters and compilers have blurred somewhat with the introduction of languages whose tools generate an intermediate language which is then executed on an internal virtual machine. The traditional compiler generates machine code files which are then further processed into an application to execute. The traditional interpreter parses the source text line by line performing some action indicated by the line of source text at the time the line of source is read.

A C or C++ compiler generates object files containing binary code which are then processed by a linker into an application and executed. A Java compiler generates class files containing Java Virtual Machine byte code which are then combined into a Java application and executed.

Engines for scripting languages such as Php and JavaScript may use an internal compiler to generate an intermediate form of the source text which is then executed by an internal virtual machine. For some types of applications the intermediate form is temporarily stored or cached so that if the same script is being used by multiple threads or multiple repetions in a short time span, the overhead of rescaning the source text is reduced to improve efficiency. However these are not considered to be compilers.

Compilation usually involves the following steps:

  • Scanning - The scanner is responsible of tokenizing the source code into the smallest chunks of information (keywords, operators, brackets, variables, literals etc.).
  • Parsing - The parser is responsible with creating the Abstract Syntax Tree (AST) which is a tree representation of the code according to the source language definition.
  • Optimization - The AST representing the code is sent through various optimizers in order to optimize for speed or space (this part is optional).
  • Code generation - The code generator creates a linear translated document from the AST and the output language definition.

In many languages and compilers there are additional steps added to the process (like pre-processing), but these are language and compiler specific.

In most cases, where compilation is a part of the build/make/publish process, the output of the compiler will be sent to the linker which will produce the ready-to-use files.

Questions using this tag should be about the compilation process, not about how to write compilers for example (use the compiler tag for that).

17181 questions
33
votes
4 answers

How to check TypeScript code for syntax errors from a command line?

I have a code that generates TypeScript classes, and as a build/test step, I would like to check the generated files for syntax correctness. I have looked at TypeScript compiler options but see no such option. How can I check the syntax? I don't…
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
33
votes
2 answers

When does ahead-of-time (AOT) compilation happen?

I'm using C#.NET for a web application. I've read that JIT compilation happens at run-time, which means(correct me if I'm wrong) that the compilation will happen when the request hits IIS. Another compilation happens using csc.exe during the build…
chaudharyp
  • 3,394
  • 3
  • 26
  • 42
33
votes
6 answers

Android compilation is slow (using Eclipse)

When I change any .java file and build, the compilation takes 16 seconds. I don't understand why it should be so slow!? I enabled verbose output for Andoroid. Window > Preferences > Android > Build output > Verbose. The result output (Console >…
alex2k8
  • 42,496
  • 57
  • 170
  • 221
33
votes
8 answers

Operating System compile time

This is just a general question - I was sitting and waiting for a bit of software to compile (we use Incredibuild here but can still take 10/15 mins) and it got me wondering, does anyone know how long it took to compile Windows XP or Vista? I did…
Konrad
  • 39,751
  • 32
  • 78
  • 114
33
votes
3 answers

Maven compile mixed Java + Groovy 1.7 project, using gmaven-plugin

As per the top two answers in: maven dependencies groovy. I'm trying to compile a mixed Java 6 + Groovy project with Maven, using the GMaven-plugin from org.codehaus.gmaven. Up until yesterday we were using the old 1.6.0 version of Groovy (never…
Tim
  • 19,793
  • 8
  • 70
  • 95
33
votes
4 answers

How do I invoke the MinGW cross-compiler on Linux?

I have a project that I want to cross-compile for Windows. I have the appropriate Makefile and everything works with g++. I've run $ apt install mingw-w64 and downloaded 500 MB of packages, but I cannot find out how to actually run it. There is no…
Martin Melka
  • 7,177
  • 16
  • 79
  • 138
33
votes
2 answers

XAML Conditional Compilation

Is there an easy way to use the same conditional compilation symbol that I'm using for my c# code, in my xaml files?
Jonathan Websdale
32
votes
3 answers

What are the stages of compilation of a C++ program?

Are the stages of compilation of a C++ program specified by the standard? If so, what are they? If not, an answer for a widely-used compiler (I'd prefer MSVS) would be great. I'm talking about preprocessing, tokenization, parsing and such. What is…
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
32
votes
3 answers

The benefits / disadvantages of unity builds?

Since starting at a new company I've noticed that they use unity cpp files for the majority of our solution, and I was wondering if anyone is able to give me a definitive reason as to why and how these speed up the build process? I would've thought…
Stowelly
  • 1,260
  • 2
  • 12
  • 31
32
votes
3 answers

What does Lambda Expression Compile() method do?

I am trying to understand AST in C#. I wonder, what exactly Compile() method from this example does. // Some code skipped Expression> data = Expression.Lambda>( …
jk_
  • 5,448
  • 5
  • 25
  • 23
32
votes
3 answers

Is the compiler allowed to optimise out private data members?

If the compiler can prove that a (private) member of a class is never used, including by potential friends, does the standard allow the compiler to remove this member from the memory footprint of the class? It is self-evident that this not possible…
bitmask
  • 32,434
  • 14
  • 99
  • 159
32
votes
3 answers

What does a semi colon do after a conditional block in C#?

I recently came across this code in a project - which I assume was there by mistake: if(condition) { //Whatever... }; Note the semi colon after the closing brace. Does anyone know what the effect of this is? I assume it does not have any effect,…
Alex
  • 3,730
  • 9
  • 43
  • 94
32
votes
7 answers

Function pointers in C - nature and usage

I have just read an interesting question here that makes me wonder about two more things: Why should anyone compare function pointers, given that by conception, functions uniqueness is ensured by their different names? Does the compiler see…
Benjamin Barrois
  • 2,566
  • 13
  • 30
32
votes
5 answers

The equivalent of ./configure in Windows?

What is the equivalent of ./configure in Windows? Sometimes I download a C/C++ library and when I use the make it, it says "use ./configure" but obviously ./configure can only be used on a Linux machine and the libraries don't usually have…
Brad
  • 10,015
  • 17
  • 54
  • 77
32
votes
4 answers

How to config cmake for strip file

when I use cmake in Release mode I have the following binary: 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=485ac09b0a3aa879f88b7f5db6c00ea8d8e1eaf6,…
Fractale
  • 1,503
  • 3
  • 19
  • 34