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
30
votes
3 answers

Why does the C++ linker allow undefined functions?

This C++ code, perhaps surprisingly, prints out 1. #include std::string x(); int main() { std::cout << "x: " << x << std::endl; return 0; } x is a function prototype, which seems to be viewed as a function pointer, and C++…
chmullig
  • 13,006
  • 5
  • 35
  • 52
30
votes
3 answers

Compiling Python 3.4 is not copying pip

I have compiled Python 3.4 from the sources on Linux Mint, but for some reason it is not copying pip to its final compiled folder (after the make install). Any ideas?
Rui Lima
  • 7,185
  • 4
  • 31
  • 42
30
votes
4 answers

Why my program doesn't show compile time error when final class variable is not initialized?

For following code: public class StaticFinal { private final static int i ; public StaticFinal() {} } I get compile time error: StaticFinal.java:7: variable i might not have been initialized {} ^ 1 error Which is in…
Vishal K
  • 12,976
  • 2
  • 27
  • 38
30
votes
2 answers

Maven - How to build multiple Independent Maven projects from one project

I have 3 maven projects WebComponents DataComponents ServiceComponents When i build each of the projects i have to go into each folder and run mvn clean install on each of the projects. I have looked into multi module projects and most of the…
ziggy
  • 15,677
  • 67
  • 194
  • 287
29
votes
5 answers

compiling opencv in c++

i have a file with only import: #include #include #include "cxcore.hpp" #include "highgui.hpp" using namespace cv; using namespace std; int main( int argc, char** argv ) { } and i try to compile with g++…
nkint
  • 11,513
  • 31
  • 103
  • 174
29
votes
6 answers

`goto` in Python

I must use goto in Python. I found entrians goto but my Python implementation (CPython 2.7.1 on Mac) does not have this module, so it doesn't seem to be portable. It should at least work in all Python implementations which support CPython bytecode…
Albert
  • 65,406
  • 61
  • 242
  • 386
29
votes
10 answers

Can I check if the C# compiler inlined a method call?

I'm writing an XNA game where I do per-pixel collision checks. The loop which checks this does so by shifting an int and bitwise ORing and is generally difficult to read and understand. I would like to add private methods such as private bool…
Ben S
  • 68,394
  • 30
  • 171
  • 212
29
votes
6 answers

questions about name mangling in C++

I am trying to learn and understand name mangling in C++. Here are some questions: (1) From devx When a global function is overloaded, the generated mangled name for each overloaded version is unique. Name mangling is also applied to variables.…
Tim
  • 1
  • 141
  • 372
  • 590
29
votes
6 answers

How to resolve fatal error LNK1000: Internal error during IncrBuildImage?

I am trying to recompile solution file for memcached project on Windows 7 64 bit with Visual Studio 2008 and got the following error: 1>LINK : fatal error LNK1000: Internal error during IncrBuildImage 1> Version 9.00.21022.08 1> ExceptionCode …
Roman Kagan
  • 10,440
  • 26
  • 86
  • 126
29
votes
1 answer

Can using UndecidableInstances pragma locally have global consequences on compilation termination?

Suppose a Haskell library designer decides to use UndecidableInstances for some reason. The library compiles fine. Now suppose some program uses the library (like defines some instances of its type classes), but doesn't use the extension. Can it…
Petr
  • 62,528
  • 13
  • 153
  • 317
29
votes
4 answers

Are there any disadvantages to "multi-processor compilation" in Visual Studio?

Are there any disadvantages, side effects, or other issues I should be aware of when using the "Multi-processor Compilation" option in Visual Studio for C++ projects? Or, to phrase the question another way, why is this option off by default in…
JBentley
  • 6,099
  • 5
  • 37
  • 72
28
votes
1 answer

WPF - Compilation error: Tags of type 'PropertyArrayStart' are not supported in template sections

Ordinarily I wouldn't just post an error message on SO, but after a Google search only found one hit, I thought I'd at least open the floor for this error here on SO. I have a custom control called Sparkline with a dependency property called Values…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
28
votes
9 answers

WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.6.16

I can’t work out why I’m getting this error from Nokogiri when I start up Rails. From the little I know, it seems like something else is causing an older version of libxml2 to be loaded, which Nokogiri then ends up using, rather than the version it…
Gareth
  • 133,157
  • 36
  • 148
  • 157
28
votes
3 answers

Does C++ compile to assembly?

Does C++ code compile to assembly code? If we have C++ code, will we be able to get assembly code?
Ata
  • 12,126
  • 19
  • 63
  • 97
28
votes
5 answers

Why does C++ linking use virtually no CPU?

On a native C++ project, linking right now can take a minute or two. Yet, during this time CPU drops from 100% during compilation to virtually zero. Does this mean linking is primarily a disk activity? If so, is this the main area an SSD would make…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589