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

new types may not be defined in a return type - C++

I am confused I think on C++ class structure. I have a .h called FxMathFunctions.h and a .cpp called FxMathFunctions.cpp the .h starts like: class FxMathFunctions { public: FxMathFunctions(); ~FxMathFunctions(); and in the…
jDOG
  • 1,191
  • 5
  • 12
  • 13
56
votes
4 answers

Can Cython compile to an EXE?

I know what Cythons purpose is. It's to write compilable C extensions in a Python-like language in order to produce speedups in your code. What I would like to know (and can't seem to find using my google-fu) is if Cython can somehow compile into…
ThantiK
  • 1,582
  • 4
  • 17
  • 31
54
votes
10 answers

Are functional languages inherently slow?

Why are functional languages always tailing behind C in benchmarks? If you have a statically typed functional language, it seems to me it could be compiled to the same code as C, or to even more optimized code since more semantics are available to…
Steve
54
votes
4 answers

How to check if a Perl script doesn't have any compilation errors?

I am calling many Perl scripts in my Bash script (sometimes from csh also). At the start of the Bash script I want to put a test which checks if all the Perl scripts are devoid of any compilation errors. One way of doing this would be to actually…
user13107
  • 3,239
  • 4
  • 34
  • 54
53
votes
16 answers

java.lang.Exception: No tests found matching Method using Intellij IDEA

I am experiencing a strange behavior of Intellij IDEA 2016.3. Having a class with method foo and a JUnit test for the method when I get java.lang.Exception: No tests found matching Method foo when running the test. After I do mvn test it succeeds…
Arthur Eirich
  • 3,368
  • 9
  • 31
  • 63
53
votes
5 answers

What can I do to my scala code so it will compile faster?

I have a large scala code base. (https://opensource.ncsa.illinois.edu/confluence/display/DFDL/Daffodil%3A+Open+Source+DFDL) It's like 70K lines of scala code. We are on scala 2.11.7 Development is getting difficult because compilation - the…
Mike Beckerle
  • 725
  • 5
  • 13
53
votes
6 answers

How to handle large Swift Project?

After iPhone app that I'm writing in Swift become quite big (> 150 .swift files + various Objective-C libs), Xcode start behave pretty badly: every second compilation I get various errors, e.g.: Command failed due to signal: Segmentation fault:…
Alexey Globchastyy
  • 2,175
  • 1
  • 15
  • 19
53
votes
4 answers

How do you export your finished application from Xcode?

I feel silly for having to ask this. I've got an application to a point where I want to send someone a beta to test on their machine, but I don't know how to get Xcode to produce a .app file for me to send to them. Help?
Kaji
  • 2,220
  • 6
  • 30
  • 45
52
votes
1 answer

What does the compile-time error "Undefined symbols for architecture x86_64" mean?

I'm trying to program a graph class using an adjacent list from an example in my C++ text book, and when I compile using this command: Code: g++ -o prog program.cpp ...I get the following error: Undefined symbols for architecture x86_64: "_main",…
gravity black
  • 646
  • 1
  • 5
  • 12
52
votes
4 answers

Automatic #defines according to Debug/Release config in Visual Studio

I have debug output in my program like this: #define DEBUG ... #ifdef DEBUG std::cout << "[RE_words] " << m_re << std::endl; #endif and DEBUG is defined in my program manually. I always comment out the line when I make a release version. In…
Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
52
votes
3 answers

Microsoft Visual C++ Compiler for Python 3.4

I know that there is a "Microsoft Visual C++ Compiler for Python 2.7" but is there, currently or planned, a Microsoft Visual C++ Compiler for Python 3.4 or eve Microsoft Visual C++ Compiler for Python 3.x for that matter? It would be supremely…
Rusty Weber
  • 1,541
  • 1
  • 19
  • 32
52
votes
4 answers

Understanding STG

The design of GHC is based on something called STG, which stands for "spineless, tagless G-machine". Now G-machine is apparently short for "graph reduction machine", which defines how laziness is implemented. Unevaluated thunks are stored as an…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
52
votes
3 answers

Undefined reference error for template method

This has been driving me mad for the past hour and a half. I know it's a small thing but cannot find what's wrong (the fact that it's a rainy Friday afternoon, of course, does not help). I have defined the following class that will hold…
recipriversexclusion
  • 13,448
  • 6
  • 34
  • 45
51
votes
3 answers

CMake Multiarchitecture Compilation

I want to know how I could write a CMake setup which allows compilation for both x86 and x64 architectures using any compiler and OS.
OniLink
  • 733
  • 1
  • 7
  • 9
51
votes
5 answers

Compiling php with curl, where is curl installed?

I need to specify a directory when compiling php with --with-curl= The curl binary is located at /usr/bin/curl curl -V gives me curl 7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 locate curl gives…
HyderA
  • 20,651
  • 42
  • 112
  • 180