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
41
votes
5 answers

Maven: skip test-compile in the life cycle?

I have project that I set to build with the test-jar and normal jar by using this setting: org.apache.maven.plugins maven-jar-plugin
fei
  • 2,224
  • 9
  • 31
  • 36
41
votes
2 answers

Compiling a static executable with CMake

for a project I need to create an executable that includes all the libraries that I used (opencv, cgal) in order to execute it on a computer that has not those libraries. Currently, this is my CMakeLists.txt (I use…
Andrea
  • 1,597
  • 3
  • 18
  • 24
41
votes
3 answers

Tentative definitions in C and linking

Consider the C program composed of two files, f1.c: int x; f2.c: int x=2; My reading of paragraph 6.9.2 of the C99 standard is that this program should be rejected. In my interpretation of 6.9.2, variable x is tentatively defined in f1.c, but this…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
40
votes
3 answers

How to compile dynamic library for a JNI application on linux?

I'm using Ubuntu 10.10 So that's what I did. Hello.java: class Hello { public native void sayHello(); static { System.loadLibrary("hellolib"); } public static void main(String[] args){ Hello h = new…
dierre
  • 7,140
  • 12
  • 75
  • 120
40
votes
1 answer

Haskell program outputs `<>`

I wrote a Haskell program that preforms a binary search on a list. At least that's what I thought it does. When I compiled the program with ghc v7.6.3 and ran the program I got the following output: progname: <> What on earth does this output…
recursion.ninja
  • 5,377
  • 7
  • 46
  • 78
40
votes
3 answers

How are Haskell programs compiled and executed internally?

I'm having trouble understanding how Haskell (GHC) compiles programs, and how those programs are run. GHC is the canonical example of a nontrivial program written in Haskell. However, parts of GHC seem not to be written in Haskell, namely the…
David
  • 8,275
  • 5
  • 26
  • 36
39
votes
1 answer

Compile lua code, store bytecode then load and execute it

I'm trying to compile a lua script that calls some exported functions, save the resulting bytecode to a file and then load this bytecode and execute it, but I haven't found any example on how to do this. Is there any example available on how to do…
WoLfulus
  • 1,948
  • 1
  • 14
  • 21
39
votes
22 answers

Is it possible to write a program without using main() function?

I keep getting this question asked in interviews: Write a program without using main() function? One of my friends showed me some code using Macros, but i could not understand it. So the question is: Is it really possible to write and compile a…
Expert Novice
  • 1,943
  • 4
  • 22
  • 47
39
votes
3 answers

How can I get rid of the warning import/no-anonymous-default-export in React?

I get the warning in the consle:"Assign object to a variable before exporting as module default import/no-anonymous-default-export." This is coming from my .js functions which export several functions as default. I am not sure how to get rid of,…
YoungDad
  • 765
  • 2
  • 6
  • 14
39
votes
2 answers

How to compile a single Java file

I have searched this, but I could'n find or understand what I found. Now I'm not a Java programmer, but I have the need to compile a single Java file into an existing (compiled) Java program. The source of this Java code is not available to me,…
Aidiakapi
  • 6,034
  • 4
  • 33
  • 62
39
votes
2 answers

How to recompile with -Xlint:unchecked in Ant build task?

When I run the "compile" target of my Ant "build.xml" file, then I get the following message: Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. My compile target is the following: …
Benny Code
  • 51,456
  • 28
  • 233
  • 198
39
votes
2 answers

How to make IntelliJ IDEA recognise code created by macros?

Background I have an sbt-managed Scala project that uses the usual sbt project layout for Scala projects with macros, i.e., a subproject that contains the macros a main project that is the actual application and that depends on the macro subproject.…
39
votes
5 answers

How to link to a static library in C?

I use code::blocks to compile my static library. The output result is a libstatic.a file. Now, how do I link to my library to use functions that were compiled? (I tried to use #include "libstatic.a" but my project doesn't compile)
user188276
39
votes
11 answers

How to compile a Python package to a dll

Well, I have a Python package. I need to compile it as dll before distribute it in a way easily importable. How? You may suggest that *.pyc. But I read somewhere any *.pyc can be easily decompiled! Update: Follow these: 1) I wrote a python…
Developer
  • 8,258
  • 8
  • 49
  • 58
39
votes
8 answers

Fastest way to debug Firefox addons during development

Debugging a Firefox addon is a slow process: (1) edit source code in a JS editor (2) package into XPI using a build script (3) drag into Firefox to install (4) restart Firefox (5) open the JavaScript Debugger Can we speeden up the process? Like…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607