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
69
votes
10 answers

Determining C executable name

When we are compiling a C program the output is stored in a.out. How can we redirect the compiled output to another file?
arun
69
votes
5 answers

How can I compile and run c# program without using visual studio?

I am very new to C#. I have just run C# 'Hello World' program using Visual Studio. Can I run or compile a C# program without using Visual Studio? If it is possible, then which compiler should I use? Thanks
A.s. Bhullar
  • 2,680
  • 2
  • 26
  • 32
68
votes
6 answers

Two dimensional array initializer followed by square brackets

I have a problem understanding this piece of code: int[] it = new int[][]{{1}}[0]; Why is it compileable, and how can I understand such a declaration?
user2654250
  • 683
  • 5
  • 9
67
votes
5 answers

How do I compile a PyQt script (.py) to a single standalone executable file for windows (.exe) and/or linux?

I started to fiddle with PyQt, and made a "beautiful" script from the pyqt whitepaper example app (pastebin) It works perfectly in Windows and Linux (with qt environment already installed on both). Now my question is: Since I am trying to use Qt…
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
67
votes
2 answers

Why does gcc not implicitly supply the -fPIC flag when compiling static libraries on x86_64

I've had numerous problems compiling shared objects that link statically against static libraries. This problem only shows up on x84_64 platforms. When doing the same compilation work on x86_32 I do not have any problems. Perhaps this is a OS…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
66
votes
4 answers

Why are arrays Objects, but can not be used as a base class?

The Java language specification specifies that In the Java programming language arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an…
Heisenberg
  • 3,153
  • 3
  • 27
  • 55
66
votes
5 answers

How do I link object files in C? Fails with "Undefined symbols for architecture x86_64"

So I'm trying trying to use a function defined in another C (file1.c) file in my file (file2.c). I'm including the header of file1 (file1.h) in order to do this. However, I keep getting the following error whenever I try to compile my file using…
adi
  • 843
  • 1
  • 8
  • 8
65
votes
5 answers

what is cross compilation?

what is cross compilation?
debugger
65
votes
2 answers

Infinite loop breaks method signature without compilation error

I am wondering why is the following code allowed in Java, without getting compilation error? In my opinion, this code breaks method signature by not returning any String. Could someone explain what I'm missing here? public class Loop { private…
Simo Martomaa
  • 526
  • 4
  • 9
64
votes
4 answers

Grails BuildConfig.groovy, difference between build, compile, and runtime?

What's the difference between build, runtime, and compile, in BuildConfig.groovy (1.3.7) grails.project.dependency.resolution = { plugins { build "acme:acme-cache:latest.integration" } dependencies { build…
raffian
  • 31,267
  • 26
  • 103
  • 174
64
votes
17 answers

error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath

I can't compile my Android Kotlin project. I have no idea what is this... Gradle log: error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: class…
junioregis
  • 901
  • 1
  • 6
  • 9
64
votes
11 answers

How do I define a compile-time *only* classpath in Gradle?

Can someone please give me a simple build.gradle example of how I can specify compile-time-only classes that are not included in the runtime deployment (war). Gradle seems to have gotten this the wrong way around since 'runtime' inherits from…
Alex Worden
  • 3,374
  • 6
  • 34
  • 34
63
votes
1 answer

Why is `abs()` implemented differently?

I've had a super frustrating bug in my code for the past few weeks. My code would work exactly as expected on my computer, but as soon as I farmed it out to the HPC server, it would produce weird results. I've boiled it down to this: on my computer…
Bamboo
  • 973
  • 7
  • 17
63
votes
20 answers

Troubleshooting "program does not contain a static 'Main' method" when it clearly does...?

My MS Visual C# program was compiling and running just fine. I close MS Visual C# to go off and do other things in life. I reopen it and (before doing anything else) go to "Publish" my program and get the following error message: Program…
adeena
  • 4,027
  • 15
  • 40
  • 52
63
votes
1 answer

Undefined Symbols for architecture x86_64: Compiling problems

So I am trying to start an assignment, my professor gives us a Main.cpp, Main.h, Scanner.cpp, Scanner.h, and some other utilities. My job is to create a Similarity class to compare documents using the cosine and Jaccard coefficients. However, I can…
Trevor Hutto
  • 2,112
  • 4
  • 21
  • 29