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
38
votes
6 answers

How does one compile single file Xcode 4?

While I used to compile a single source file with Cmd+K in prior versions of Xcode, how does one do the same in Xcode 4? (Note that this is different than preprocessing or showing the disassembly of the file.) If compiling from a command line is…
sergey
  • 579
  • 1
  • 5
  • 9
38
votes
3 answers

How to statically link a library when compiling a python module extension

I would like to modify a setup.py file such that the command "python setup.py build" compiles a C-based extension module that is statically (rather than dynamically) linked to a library. The extension is currently dynamically linked to a number of…
Matthew Walker
  • 2,527
  • 3
  • 24
  • 30
38
votes
5 answers

Is it possible to configure CLion to compile source files in a project independently?

I am currently doing some Project Euler challenges in C using the JetBrains CLion IDE. When I completed these in Python and Java (in PyCharm and IntelliJ, respectively), I was always able to create a single project named "ProjectEuler" and add any…
nidorion
  • 383
  • 1
  • 4
  • 5
38
votes
2 answers

fatal error: sqlite3.h: No such file or directory

I'm trying to build a C application through cross compiling for a Zynq board (ARM architecture). When I type make without mentioning the ARM arch, it works fine on my laptop. But as soon as I modify the Makefile, I get an error saying: main.c:20:43:…
user2263752
  • 469
  • 1
  • 6
  • 8
38
votes
3 answers

Golang - Difference between "go run main.go" and compilation

After writing some scripts in Go I asked myself if there is any difference between the compilation of a .go-file and the later execution and the go run FILE.go command in terms of performence etc. Are there any advantages if I start a webservice…
user3147268
  • 1,814
  • 7
  • 26
  • 39
38
votes
3 answers

PHP 5.4.7 Compiling ext php_printer

My Knowledge base is, I can get around in php. I never worked with C, C++, C# or any compilers. I Upgraded from XAMPP 1.7.3, which used php 5.3, to 1.8.1 which includes: Apache 2.4.3 MySQL 5.5.27 PHP 5.4.7 It is being installed on Windows 7 Pro,…
dBaker
  • 383
  • 1
  • 3
  • 6
37
votes
3 answers

How does GCC's '-pg' flag work in relation to profilers?

I'm trying to understand how the -pg (or -p) flag works when compiling C code with GCC. The official GCC documentation only states: -pg Generate extra code to write profile information suitable for the analysis program gprof. You must use this…
Trevor
  • 1,858
  • 4
  • 21
  • 28
37
votes
6 answers

Why does Delphi's compilation speed degrade the longer it's open, and what can I do about it?

My company has been running a large project on Delphi for more than a decade. Our codebase has been growing over the years and now stands at around 4 million lines of code. Compilation speed is becoming an issue. We've spent time weeding out unit…
John
  • 373
  • 3
  • 5
37
votes
2 answers

why do we need the shared library during compile time

Why we need the presence of the shared library during the compile time of my executable? My reasoning is that since shared library is not included into my executable and is loaded during the runtime, it is not supposed to be needed during compile…
Gab是好人
  • 1,976
  • 1
  • 25
  • 39
37
votes
1 answer

How is GCC IR different from LLVM IR?

Why do people prefer LLVM IR, and how exactly is it different from the GCC IR? Is target dependency a factor here? I'm a complete newbie to compilers, and wasn't able to find anything relevant even after many hours of searching for an answer. Any…
lost_wanderer
  • 471
  • 5
  • 8
37
votes
3 answers

Can I use shared library created in C++ in a C program?

I am creating programs using C. However, I require to use a lot of libraries that have API's only for C++. So, is it possible that I can create a shared object in C++ and then access its functionality using C? The only data I would be passing and…
coolharsh55
  • 1,179
  • 4
  • 12
  • 27
36
votes
1 answer

What is module option in tsconfig used for?

I am trying to understand the typescript module compiler option. I went through typescript documentation - docs It says module option is to Specify module code generation. What does that mean? Does it mean if I put module option as commonjs, then…
troglodyte07
  • 3,598
  • 10
  • 42
  • 66
36
votes
5 answers

Why Compile to an Object File First?

In the last year I've started programming in Fortran working at a research university. Most of my prior experience is in web languages like PHP or old ASP, so I'm a newbie to compile statements. I have two different code I'm modifying. One has an…
tomshafer
  • 795
  • 3
  • 8
  • 12
36
votes
2 answers

How to determine what C++ standard is the default for a C++ compiler?

It is frequently mentioned that the -std flag should be used to specify the standard that one wishes to use when compiling a C++ program (e.g., -std=c++11 or -std=gnu++11). A related question that is not typically addressed (at least as far as I can…
AnInquiringMind
  • 773
  • 1
  • 7
  • 13
36
votes
15 answers

Is it possible to compile and execute new code at runtime in .NET?

Note: Mathematical expression evaluation is not the focus of this question. I want to compile and execute new code at runtime in .NET. That being said... I would like to allow the user to enter any equation, like the following, into a text box: x…
raven
  • 18,004
  • 16
  • 81
  • 112