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

MinGW c++ compiler zlib1.dll missing error?

I have just started to learn C++ for school, and I'm trying to download the compiler MinGW to compile my source code. However, every time I try to compile a program an error message shows up saying that zlib1.dll is missing. This is the error…
GamefanA
  • 1,555
  • 2
  • 16
  • 23
32
votes
9 answers

C/C++ How Does Dynamic Linking Work On Different Platforms?

How does dynamic linking work generally? On Windows (LoadLibrary), you need a .dll to call at runtime, but at link time, you need to provide a corresponding .lib file or the program won't link... What does the .lib file contain? A description of…
Charlie
  • 4,197
  • 5
  • 42
  • 59
31
votes
4 answers

What is "object" in "object file" and why is it called this way?

I was asked a question: "What is an 'object file'?". After looking at Wiki, I only know that it contains objects. But what are those objects and why someone called them that way?
sthlm58
  • 1,142
  • 1
  • 9
  • 28
31
votes
5 answers

Why does march=native not work on Apple M1?

Whenever I try to compile any C++ program with march=native on a Macbook with a M1 chip, I get the following error when using clang: clang: error: the clang compiler does not support '-march=native' However, it used to work on an older Macbook with…
Momo
  • 444
  • 1
  • 4
  • 11
31
votes
5 answers

Is there an interactive interpreter for Java?

I want to execute java commands interactively from shell: is there a way to do so?
Mohamed Khamis
  • 7,731
  • 10
  • 38
  • 58
31
votes
2 answers

Compile multiple C files with make

(I am running Linux Ubuntu 9.10, so the extension for an executable is executablefile.out) I am just getting into modular programming (programming with multiple files) in C and I want to know how to compile multiple files in a single makefile. For…
Mohit Deshpande
  • 53,877
  • 76
  • 193
  • 251
31
votes
3 answers

How to improve Golang compilation speed?

I'm trying to find a way to make the compilation of a Go program faster. It is currently about 30 seconds, which makes it slow to work with the project. When I run go build -v, I see that most of the time is spent compiling go-sqlite3 (which links…
laurent
  • 88,262
  • 77
  • 290
  • 428
31
votes
1 answer

Can I compile a cuda program without having a cuda device

Is it possible to compile a CUDA program without having a CUDA capable device on the same node, using only NVIDIA CUDA Toolkit...?
DEV
  • 2,106
  • 3
  • 25
  • 40
31
votes
8 answers

Javac is not found

I'm running Windows 8 and I can not get javac to work. I have set my PATH in environmental variables to C:\Program Files (x86)\Java\jdk1.7.0_17\bin I have tried both with and without ';' but to no avail. I recently had this issue on my desktop…
Arktri
  • 577
  • 2
  • 6
  • 9
31
votes
4 answers

Get rid of "gcc - /usr/bin/ld: warning lib not found"

I have the following warning during link: /usr/bin/ld: warning: libxxx.so.6, needed by /a/b/c/libyyy.so, not found (try using -rpath or -rpath-link) Setting environment variable LD_LIBRARY_PATH=path_to_libxxx.so.6 silence the warning (adding…
dimba
  • 26,717
  • 34
  • 141
  • 196
30
votes
2 answers

What is the main difference between a Compiler and a Transpiler?

What are the main differences between a Compiler and a Transpiler? Please could you provide some examples of both?
Dawlatzai Ghousi
  • 3,780
  • 2
  • 20
  • 26
30
votes
13 answers

Why use #if 0 for block commenting out?

Reverse engineering code and I'm kind of appalled at the style, but I wanted to make sure there's no good reason for doing these things.... Is it just me or is this a horrible coding style if ( pwbuf ) sprintf(username,"%s",pwbuf->pw_name); else…
Jason R. Mick
  • 5,177
  • 4
  • 40
  • 69
30
votes
1 answer

What do the numbers mean in the preprocessed .i files when compiling C with gcc?

I am trying to understand the compiling process. We can see the preprocessor intermediate file by using: gcc -E hello.c -o hello.i or cpp hello.c > hello.i I roughly know what the preprocessor does, but I have difficulties understanding the…
Conan
  • 561
  • 5
  • 17
30
votes
5 answers

Visual Studio Code: compile typescript module

I've just downloaded the new Visual Studio Code and my first impression is very positive. For typescript, intellisense works beautifully. However, there is a strange problem: VS Code doesn't seem to be able to compile typescript modules. This…
lhk
  • 27,458
  • 30
  • 122
  • 201
30
votes
3 answers

Undefined reference to global variable during linking

I am trying to compile a program which is divided into 3 modules, corresponding to 3 source files: a.c, b.c, and z.c. z.c contains the main() function, which calls functions in a.c and b.c. Furthermore, a function in a.c calls a function in b.c, and…
freieschaf
  • 530
  • 1
  • 5
  • 13