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
27
votes
1 answer

When using two frames in emacs, how do I prevent the compilation buffer from showing up in both?

I work with two monitors, and often use emacs with two frames open; one for each monitor. each frame is split into two side-by-side windows, like so: a | b <-- frame 1 in monitor 1 ------- c | d <-- frame 2 in monitor 2 When I hit my…
SuperElectric
  • 17,548
  • 10
  • 52
  • 69
27
votes
4 answers

Are unnecessary include files an overhead?

I have seen a couple of questions on how to detect unnecessary #include files in a C++ project. This question has often intrigued me, but I have never found a satisfactory answer. If there are some header files included which, are not being used in…
Ujjwal Aryan
  • 3,827
  • 3
  • 20
  • 31
27
votes
5 answers

Javac "cannot find symbol"

I've the root directory like this : ├── classes └── src └── vehicles ├── Bicycle.java └── BicycleMain.java Bicycle.java package vehicles; public class Bicycle { public int cadence; public int gear; public int speed; …
andrian
  • 423
  • 1
  • 8
  • 15
27
votes
5 answers

How to run Java program in command prompt

I created a Java project to call a Web service. It has one Main java file and another class file. I have used some jar files for HTTP client. In Eclipse it runs fine. I need to run the Java program in command prompt by passing some arguments. In…
Vignesh
  • 2,295
  • 7
  • 33
  • 41
27
votes
5 answers

How can I build my C extensions with MinGW-w64 in Python?

So I have a few Python C extensions I have previously built for and used in 32 bit Python running in Win7. I have now however switched to 64 bit Python, and I am having issues building the C extension with MinGW-w64. I made the changes to distutils…
c00kiemonster
  • 22,241
  • 34
  • 95
  • 133
27
votes
4 answers

Java code transform at compile time

I would like to transform java source code at compile time just before passing the source code to the compiler. In other word I would like to create a preprocessor able to transform "bla bla bla" into any other code such as: new MyClass("bla", 3)…
Martin Pernollet
  • 2,285
  • 1
  • 28
  • 39
26
votes
1 answer

Boost: How bjam constructs a library name?

I was looking in the jam files, how the name of library is constructed. Example: libboost_log-mgw46-mt-1_48.dll I would like to ignore the last part, how to pass linker the -o parameter with my constructed name. I have few versions and linking in a…
Sandro Grm
  • 261
  • 3
  • 4
26
votes
2 answers

Compile C# Code In The Application

I want some code that compiles the code that is in my TextBox (for example). What I mean is I want to compile code after running the program. How can I do this?
ahmadali shafiee
  • 4,350
  • 12
  • 56
  • 91
26
votes
1 answer

What exactly happens when compiling with -funwind-tables?

From: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html -fexceptions: Enable exception handling. Generates extra code needed to propagate exceptions. For some targets, this implies GCC generates frame unwind information for all…
Pendyala
  • 585
  • 1
  • 6
  • 17
26
votes
5 answers

Using an object after std::move doesn't result in a compilation error

After std::move is called on an object, why doesn't the language cause a compilation error if the object is used after? Is it because it is not possible for compiler to detect this condition?
Jubin Chheda
  • 534
  • 4
  • 11
26
votes
8 answers

Freeze a python script for every OS

In the last few years I've written a nice little program in python and now I'd like to distribute it, but my first attempt didn't encounter much enthusiasm, since many potential users didn't like the idea of downloading and installing python and all…
GRB
  • 425
  • 1
  • 6
  • 20
26
votes
7 answers

How much do forward declarations affect compile time?

I am very interested in some studies or empirical data that shows a comparison of compilation times between two c++ projects that are the same except one uses forward declarations where possible and the other uses none. How drastically can forward…
JoshD
  • 12,490
  • 3
  • 42
  • 53
26
votes
3 answers

npm with node-sass and autoprefixer

I use node-sass to compile all my Sass files to a master.css. This works well but now I want to add prefixes. I would like to use only the npm, no Gulp or Grunt. Here my package.json file: { "name": "xxxxxx.com", "version": "1.0.0", …
QJan84
  • 786
  • 3
  • 9
  • 22
26
votes
7 answers

How can adding a function call cause other symbols to become undefined when linking?

I'm hoping someone will be able to help troubleshoot what I think is a linker script issue. I'm encountering a strange problem after adding a call to a new function. Without the function call, my object files link correctly, however, with the new…
owst
  • 518
  • 4
  • 14
26
votes
4 answers

What does the :compiler command do in Vim?

I recently found that there is a command in Vim called compiler. You can call it with any common compiler (for example, :compiler gcc, :compiler php, etc.), but it doesn't seem to have any immediate effect. I searched on the manpages but didn't find…
Martín Fixman
  • 9,055
  • 9
  • 38
  • 46