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
28
votes
2 answers

Are compilers built with previous version of themselves protected from code injection?

I was wondering if today's modern compilers like MS cc, gcc, clang, icc, newer versions were built with the current version of the same compiler? Because of course of this…
v.oddou
  • 6,476
  • 3
  • 32
  • 63
28
votes
2 answers

Cython setup.py for several .pyx

I would like to cythonize faster. Code for one .pyx is from distutils.core import setup from Cython.Build import cythonize setup( ext_modules = cythonize("MyFile.pyx") ) What if i want to cythonize several files with ext .pyx, that i will…
kiriloff
  • 25,609
  • 37
  • 148
  • 229
28
votes
1 answer

Why does classname$1.class generate in this situation?

I wrote the following code to implement the Singleton pattern: public final class Test { static final class TestHolder { private static final Test INSTANCE = new Test(); } private Test() {} public static Test…
handrenliang
  • 1,047
  • 1
  • 10
  • 21
28
votes
1 answer

Understanding a Makefile with $(basename $(notdir $@))

I am trying to understand a Makefile, but I don't understand the recipe line with the comment. ... ... sample.a: cd ../$(basename $(notdir $@)) && make ##i don't understand this ... ... I'm still a newbie at this. Can you give me a very…
user2297764
28
votes
4 answers

Scala and forward references

Possible Duplicate: Scala: forward references - why does this code compile? object Omg { class A class B(val a: A) private val b = new B(a) private val a = new A def main(args: Array[String]) { println(b.a) } } the…
jdevelop
  • 12,176
  • 10
  • 56
  • 112
28
votes
2 answers

How to change maven build directory?

I have a maven project which I compile with Netbeans. I there a way to specify a different build directory where the compiled binary code is copied after compilation?
user1285928
  • 1,328
  • 29
  • 98
  • 147
27
votes
5 answers

Is a Linux executable "compatible" with OS X?

If you compile a program in say, C, on a Linux based platform, then port it to use the MacOS libraries, will it work? Is the core machine-code that comes from a compiler compatible on both Mac and Linux? The reason I ask this is because both are…
bgroenks
  • 1,859
  • 5
  • 34
  • 63
27
votes
5 answers

Compile code using JavaFX 2.0 (using command line)

I wonder how to compile code using JavaFX, from a Windows shell. I have this code in fxservidor.java: public class Fxservidor extends Application { /** * @param args the command line arguments */ public static void main(String[]…
Jhuaraya
  • 271
  • 1
  • 3
  • 3
27
votes
2 answers

Magento died after compilation: how to disable using compiled files without admin panel access?

Tried to compile Magento 1.6 here: Magento admin panel, System, Tools, Compilation It compiled and then I enabled it. After that, site died. Here's the stack (but that's not important) Warning: include_once(Mage_Core_functions.php)…
Dmitry
  • 3,861
  • 5
  • 20
  • 21
27
votes
2 answers

How to compile .c code from Cython with gcc

Now that I've successfully installed Cython on Windows 7, I try to compile some Cython code using Cython, but gcc makes my life hard. cdef void say_hello(name): print "Hello %s" % name Using gcc to compile the code throws dozens of undefined…
Niklas R
  • 16,299
  • 28
  • 108
  • 203
27
votes
3 answers

Learning incremental compilation design

There are a lot of books and articles about creating compilers which do all the compilation job at a time. And what about design of incremental compilers/parsers, which are used by IDEs? I'm familiar with first class of compilers, but I have never…
Ilya Lakhin
  • 1,904
  • 1
  • 16
  • 31
27
votes
4 answers

Templates: Use forward declarations to reduce compile time?

I have to deal with a library that consists of many templated classes, which are of course all implemented in header files. Now I'm trying to find a way to reduce the unbearably long compile times that come from the fact that I pretty much have to…
Frank
27
votes
3 answers

Is it possible to define a C macro in a makefile?

Is it possible to put the equivalent of #define VAR (in a C program) into a makefile, so that one can control which part of the program should be compiled?
Richard
  • 14,642
  • 18
  • 56
  • 77
27
votes
3 answers

Static const variable declaration in a header file

If I declare static const variable in header file like this: static const int my_variable = 1; and then include this header in more than one .c files, will compilator make new instance per each file or will be "smart" enough to see it is const and…
Michał
  • 691
  • 1
  • 5
  • 22
27
votes
6 answers

Compile a single file under CMake project?

I'm developing a C++ project which is going to be enclosed on a bigger one. I've seen that on the bigger project (is a Qt application and it's being generated from qmake) I am able to compile a single file from the linux command line, just entering…
pacorrop
  • 547
  • 1
  • 4
  • 10