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
226
votes
9 answers

Is Java a Compiled or an Interpreted programming language ?

In the past I have used C++ as a programming language. I know that the code written in C++ goes through a compilation process until it becomes object code "machine code". I would like to know how Java works in that respect. How is the user written…
Eduardo
224
votes
6 answers

How to fix error with xml2-config not found when installing PHP from sources?

When I try to install php 5.3 stable from source on Ubuntu (downloading compressed installation file from http://www.php.net/downloads.php) and I run ./configure I get this error: configure: error: xml2-config not found. Please check your libxml2…
TroodoN-Mike
  • 15,687
  • 15
  • 55
  • 78
221
votes
22 answers

Why is Swift compile time so slow?

I'm using Xcode 6 Beta 6. This is something that's been bugging me for some time now, but it's reaching a point where it's barely usable now. My project is starting to have a decent size of 65 Swift files and a few bridged Objective-C files (which…
apouche
  • 9,703
  • 6
  • 40
  • 45
219
votes
4 answers

How to create a shared library with cmake?

I have written a library that I used to compile using a self-written Makefile, but now I want to switch to cmake. The tree looks like this (I removed all the irrelevant files): . ├── include │   ├── animation.h │   ├── buffers.h │   ├── ... │   ├──…
Florian M
  • 2,815
  • 3
  • 17
  • 14
214
votes
7 answers

Is it possible to dynamically compile and execute C# code fragments?

I was wondering if it is possible to save C# code fragments to a text file (or any input stream), and then execute those dynamically? Assuming what is provided to me would compile fine within any Main() block, is it possible to compile and/or…
esac
  • 24,099
  • 38
  • 122
  • 179
212
votes
4 answers

Why does a Java class compile differently with a blank line?

I have the following Java class public class HelloWorld { public static void main(String []args) { } } When I compile this file and run a sha256 on the resulting class file I get 9c8d09e27ea78319ddb85fcf4f8085aa7762b0ab36dc5ba5fd000dccb63960ff…
KNejad
  • 2,376
  • 2
  • 14
  • 26
204
votes
17 answers

Compiling/Executing a C# Source File in Command Prompt

How do you compile and execute a .cs file from a command-prompt window?
Sajal Dutta
  • 18,272
  • 11
  • 52
  • 74
203
votes
28 answers

WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'

Suddenly when Syncing Gradle, I get this error: WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'. It will be removed at the end of 2019. For more information, see…
198
votes
5 answers

What's an object file in C?

I am reading about libraries in C but I have not yet found an explanation on what an object file is. What's the real difference between any other compiled file and an object file? I would be glad if someone could explain in human language.
Pithikos
  • 18,827
  • 15
  • 113
  • 136
189
votes
6 answers

How to enable C++17 compiling in Visual Studio?

I want to use C++17 features. How can I switch compiling from C++14 to C++17 in Microsoft Visual Studio? Or is it not available in release versions of VS?
Tudvari
  • 2,715
  • 2
  • 14
  • 33
189
votes
5 answers

Why use make over a shell script?

Make seems to me simply a shell script with slightly easier handling of command line arguments. Why is it standard to run make instead of ./make.sh
HoboBen
  • 2,900
  • 4
  • 21
  • 26
186
votes
15 answers

How do I show a console output/window in a forms application?

To get stuck in straight away, a very basic example: using System; using System.Windows.Forms; class test { static void Main() { Console.WriteLine("test"); MessageBox.Show("test"); } } If I compile this with default…
Wil
  • 10,234
  • 12
  • 54
  • 81
184
votes
10 answers

How can a compiler compile itself?

I am researching CoffeeScript on the website http://coffeescript.org/, and it has the text The CoffeeScript compiler is itself written in CoffeeScript How can a compiler compile itself, or what does this statement mean?
AlexanderRD
  • 2,069
  • 2
  • 11
  • 19
183
votes
3 answers

Create a single executable from a Python project

I want to create a single executable from my Python project. A user should be able to download and run it without needing Python installed. If I were just distributing a package, I could use pip, wheel, and PyPI to build and distribute it, but…
ShadowFlame
  • 2,996
  • 5
  • 26
  • 40
170
votes
8 answers

Building vs. Compiling (Java)

Thinking that the answer to this is pretty obvious but here it goes: When I am working on a small project for school (in java) I compile it. On my coop we are using ant to build our project. I think that compiling is a subset of building. Is…
sixtyfootersdude
  • 25,859
  • 43
  • 145
  • 213