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
99
votes
7 answers

Why isn't all code compiled position independent?

When compiling shared libraries in gcc the -fPIC option compiles the code as position independent. Is there any reason (performance or otherwise) why you would not compile all code position independent?
ojblass
  • 21,146
  • 22
  • 83
  • 132
99
votes
7 answers

How can I compile a Java program in Eclipse without running it?

I would like to compile my Java program in Eclipse but not to run it. I can't understand how to do it. How can I compile a Java program to .class files in Eclipse without running it?
Jonas
  • 121,568
  • 97
  • 310
  • 388
99
votes
4 answers

java compiled classes contain dollar signs

I've been using Eclipse as my IDE. I also use it to export my application into a JAR file. When I look at my classes in the JAR file, a few of my classes contain the name of that class, a dollar sign, then a number. For example: Find$1.class…
Frizinator
  • 1,351
  • 3
  • 12
  • 16
98
votes
10 answers

Java: How can I compile an entire directory structure of code ?

The use case is simple. I got the source files that were created using Eclipse. So, there is a deep directory structure, where any Java class could be referring to another Java class in the same, child, sibling or parent folder. How do I compile…
euphoria83
  • 14,768
  • 17
  • 63
  • 73
98
votes
1 answer

Splitting a Clojure namespace over multiple files

Is it possible to split a Clojure namespace over multiple source files when doing ahead-of-time compilation with :gen-class? How do (:main true) and (defn- ...) come into play?
Ralph
  • 31,584
  • 38
  • 145
  • 282
97
votes
4 answers

How do I run Java .class files?

I've compiled a HelloWorld program, and I'm using the command prompt to run it. The .class file is named HelloWorld2.class The file is located in C:\Users\Matt\workspace\HelloWorld2\bin Here's what I'm getting when I go to command prompt, and type…
Skizz
  • 1,405
  • 2
  • 11
  • 12
97
votes
5 answers

Can I compile Java to native code?

Is there any way to compile from Java to standalone (or library) machine code without requiring a JVM?
barroco
  • 3,018
  • 6
  • 28
  • 38
96
votes
7 answers

Profiling the C++ compilation process

I tend to write rather large templated header-only C++ libraries and my users commonly complain about compilation times. After thinking about the matter, it occurred to me that I have no idea where the time is going. Is there some simple way to…
Jack Poulson
  • 1,305
  • 1
  • 10
  • 13
95
votes
16 answers

How to compile a .NET application to native code?

Let's say I want to run a .NET application on a machine where the .NET framework is not available; Is there any way to compile the application to native code?
Niyaz
  • 53,943
  • 55
  • 151
  • 182
91
votes
3 answers

Disable displaying of "output window" at each compilation

In VS2010, I noticed that the "output window" is shown every time we compile the solution, even if we have had close it. In VS2008, that wasn't the case. I don't mind this output window. I prefer looking at the "Error window" only, and only if it is…
WolveFred
  • 1,623
  • 3
  • 14
  • 15
89
votes
2 answers

How do I modify a Homebrew formula?

I installed ImageMagick via Homebrew. However, due to a bug I have with my current configuration, I need to adjust the compile flags for the formula and reinstall it. How can I accomplish this?
maček
  • 76,434
  • 37
  • 167
  • 198
89
votes
13 answers

TypeScript "Compile on save" feature not working in Visual Studio 2015

The "Compile on save" feature isn't working for me after upgrading to Visual Studio 2015. When I make a change to a .ts file in my project and save, the status bar at the bottom of the IDE says Output(s) generated successfully, but the generated…
89
votes
8 answers

Is there a reason why not to use link-time optimization (LTO)?

GCC, MSVC, LLVM, and probably other toolchains have support for link-time (whole program) optimization to allow optimization of calls among compilation units. Is there a reason not to enable this option when compiling production software?
Honza
  • 1,734
  • 3
  • 16
  • 22
88
votes
13 answers

How do programmers work together on a project?

I've always programmed alone, I'm still a student so I never programmed with anyone else, I haven't even used a version control system before. I'm working on a project now that requires knowledge of how programmers work together on a piece of…
88
votes
8 answers

Why GDB jumps unpredictably between lines and prints variables as ""?

Can anyone explain this behavior of gdb? 900 memset(&new_ckpt_info,'\0',sizeof(CKPT_INFO)); (gdb) **903 prev_offset = cp_node->offset;** (gdb) **905 m_CPND_CKPTINFO_READ(ckpt_info,(char…
Arpit
  • 4,259
  • 10
  • 38
  • 43