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
62
votes
4 answers

Javascript: what's the point of RegExp.compile()?

I've got a situation where I want to get a regexp from the user and run it against a few thousand input strings. In the manual I found that the RegExp object has a .compile() method which is used to speed things up ins such cases. But why do I have…
Vilx-
  • 104,512
  • 87
  • 279
  • 422
62
votes
10 answers

How to fix JSP compiler warning: one JAR was scanned for TLDs yet contained no TLDs?

When starting the application or compiling JSP via ant, Tomcat 7 Jasper complains about superfluous or misplaced JAR file. I got below message **compile-jsp:** [jasper] Jul 31, 2012 7:15:15 PM org.apache.jasper.compiler.TldLocationsCache…
gowthaman
  • 983
  • 3
  • 9
  • 9
61
votes
2 answers

Thread.sleep inside infinite while loop in lambda doesn't require 'catch (InterruptedException)' - why not?

My question is about InterruptedException, which is thrown from the Thread.sleep method. While working with ExecutorService I noticed some weird behaviour that I don't understand; here is what I mean: ExecutorService executor =…
60
votes
8 answers

What does an object file contain?

During the various stages of compilation in C or C++, I know that an object file gets generated (i.e., any_name.o file). What does this .o file contain? I can't open it since it's a binary file. Could anybody please help me? Are the contents of the…
Vijay
  • 65,327
  • 90
  • 227
  • 319
60
votes
7 answers

How to turn makefile into JSON Compilation Database?

Say we have make files (not cmake/premake/ninja etc) for our project that do work for gcc and clang. We want to generate out from them JSON Compilation Database to feed it into clang-modernize tool. How to do such thing? (is there any parser in…
DuckQueen
  • 772
  • 10
  • 62
  • 134
59
votes
7 answers

How to compile a linux shell script to be a standalone executable *binary* (i.e. not just e.g. chmod 755)?

I'm looking for a free open source tool-set that will compile various "classic" scripting languages, e.g. Korn Shell, ksh, csh, bash etc. as an executable -- and if the script calls other programs or executables, for them to be included in the…
therobyouknow
  • 6,604
  • 13
  • 56
  • 73
59
votes
18 answers

Pros & Cons of putting all code in Header files in C++?

You can structure a C++ program so that (almost) all the code resides in Header files. It essentially looks like a C# or Java program. However, you do need at least one .cpp file to pull in all the header files when compiling. Now I know some people…
user15071
  • 3,391
  • 8
  • 31
  • 31
59
votes
1 answer

What is -ffreestanding option in gcc?

What is ffreestanding in gcc ? What is it used for ? I came across the following : gcc -ffreestanding -m32 -c kernel.c -o kernel.o and do not understand, what does it mean exactly.
saplingPro
  • 20,769
  • 53
  • 137
  • 195
58
votes
8 answers

BTF: .tmp_vmlinux.btf: pahole (pahole) is not available

Getting this error while compiling the kernel version :5.7-rc4 BTF: .tmp_vmlinux.btf: pahole (pahole) is not available Failed to generate BTF for vmlinux Try to disable CONFIG_DEBUG_INFO_BTF make: *** [Makefile:1106: vmlinux] Error 1
Sarkar_T
  • 581
  • 1
  • 4
  • 4
58
votes
2 answers

Tensorflow Compile Runs For A Long Time

So I am trying to compile TensorFlow from the source (using a clone from their git repo from 2019-01-31). I installed Bazel from their shell script…
Zonyl
  • 726
  • 5
  • 13
58
votes
18 answers

RAM drive for compiling - is there such a thing?

An answer (see below) to one of the questions right here on Stack Overflow gave me an idea for a great little piece of software that could be invaluable to coders everywhere. I'm imagining RAM drive software, but with one crucial difference - it…
Vilx-
  • 104,512
  • 87
  • 279
  • 422
58
votes
8 answers

Is there a native machine code compiler for JavaScript?

Is there a native machine code compiler for JavaScript? I'm not talking about a VM. If it doesn't exist can it be done? I am wondering if it can be compiled to binary due to the dynamic nature of the language.
the_drow
  • 18,571
  • 25
  • 126
  • 193
57
votes
6 answers

How do I create a library?

Let's say I have 10 *.hpp and *.cpp files that I need to compile a code. I know that I will need those same files for many different codes. Can I create a "package" with those files that would allow me to simply write: #include instead…
PinkFloyd
  • 2,103
  • 4
  • 28
  • 47
57
votes
1 answer

How to compile Qt 5 under Windows or Linux, 32 or 64 bit, static or dynamic on Visual Studio or g++

Just a post to help those guys trying to do that, since I don't have a blog. This works for linux too. Feel free to edit it and improve it.
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
56
votes
1 answer

ImportError: cannnot import name 'Imputer' from 'sklearn.preprocessing'

Trying to import Imputer from sklearn.preprocessing, import pandas as pd dataset = pd.read_csv('Data.csv') X = dataset.iloc[:, :-1].values y = dataset.iloc[:, 3].values #PART WHERE ERROR OCCURS:- from sklearn.preprocessing import Imputer Shows…
Vikram
  • 714
  • 1
  • 5
  • 10