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
47
votes
9 answers

node_modules/@types/node/index.d.ts(20,1): error TS1084: Invalid 'reference' directive syntax

I have a problem with typescript compilation. Has anybody else received this error? node_modules/@types/node/index.d.ts(20,1): error TS1084: Invalid 'reference' directive syntax. tsconfig.json: { "compileOnSave": false, "compilerOptions":…
heyJoe
  • 571
  • 1
  • 4
  • 4
47
votes
5 answers

Where are expressions and constants stored if not in memory?

From C Programming Language by Brian W. Kernighan & operator only applies to objects in memory: variables and array elements. It cannot be applied to expressions, constants or register variables. Where are expressions and constants stored if…
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
47
votes
22 answers

IDEA JetBrains IntelliJ - Compile error on 'make' but fine when compiled using Maven and no errors reported by IntelliJ in the class file

So I have a maven module (module-A) in IntelliJ. I recently moved some classes from it into another new maven module (module-B) and added a dependency to it. Once I had done this I also modified the signature of a method of one of the moved classes…
Ed .
  • 6,373
  • 8
  • 62
  • 82
47
votes
3 answers

what's the difference between -source and -target compatibility?

When using the Java compiler (javac), we can specify two kinds of compatibility. One is using -source and the other is using -target. What is the difference between these two? For example, -source 1.5 and -target 1.6? Also, is there any case where…
Adam Lee
  • 24,710
  • 51
  • 156
  • 236
46
votes
7 answers

Compile code fully in memory with javax.tools.JavaCompiler

I'm using the JavaCompiler from the javax.tools package (JDK 1.7) to compile some stuff on the fly, like this: compiler.run(null, null, "-cp", paths, "path/to/my/file.java"); It works but I would like to do it all in memory (e.g. pass a string with…
Sandman
  • 2,577
  • 2
  • 21
  • 32
46
votes
9 answers

How to wildcard include JAR files when compiling?

I have the following in a java file (MyRtmpClient.java): import org.apache.mina.common.ByteBuffer; and ByteBuffer is inside a JAR file (with the proper directory structure of course). That jar file and others I need are in the same directory as the…
javanewbie
45
votes
2 answers

Forcing GCC to compile .cpp file as C

I have an externally provided .cpp file. It is a mixture of C compatible code and a bit of C++ as well. The C++ code is just a wrapper around the C to take advantage of C++ features. It uses #ifdef __cplusplus macros to protect the C++ code, which…
ralight
  • 11,033
  • 3
  • 49
  • 59
45
votes
4 answers

The best way to integrate third party library in Android studio

We can find some very good open source libraries for android. I want to know what is the best way to integrate them to our own projects in Android studio. Here are some basic methods: Copy the source code and resource files into our own project. We…
Bagusflyer
  • 12,675
  • 21
  • 96
  • 179
45
votes
6 answers

How do I compile a .java with support for older versions of Java?

I want to compile my .java's (several) into one .jar that are compatible with at least Java 1.6 and newer, preferably Java 1.5 and newer versions of Java. (I have Java 1.7.0_5)
Primm
  • 1,347
  • 4
  • 19
  • 32
45
votes
2 answers

How to compile Lua scripts into a single executable, while still gaining the fast LuaJIT compiler?

How can I compile my Lua scripts into a single executable file, while also gaining the super fast performance benefits of LuaJIT? Background: My Lua scripts are for a web application I created (e.g. to host http://example.com) My current technology…
nickb
  • 9,140
  • 11
  • 39
  • 48
44
votes
9 answers

"Expected a type" error pointing to the return type of a method

I've attempted to compile, but every time I do, one method throws a strange "expected a type" error. I have a method in the header: -(ANObject *)generateSomethingForSomethingElse:(NSString *)somethingElse; The error points at the return type for…
Ollie Hirst
  • 592
  • 2
  • 6
  • 14
44
votes
4 answers

Is there a way to use maven property in Java class during compilation

I just want to use maven placeholder in my Java class at compile time in order to reduce duplication. Something like that: pom.xml 1.0 SomeVersion.java package some.company; public class…
Dmytro Chyzhykov
  • 1,814
  • 1
  • 20
  • 17
43
votes
6 answers

Is there a way to know by which Python version the .pyc file was compiled?

Is there any way to know by which Python version the .pyc file was compiled?
Aamir Rind
  • 38,793
  • 23
  • 126
  • 164
43
votes
3 answers

How are char arrays / strings stored in binary files?

When I compile this code using different compilers and inspect the output in a hex editor I am expecting to find the string "Nancy" somewhere. #include int main() { char temp[6] = "Nancy"; printf("%s", temp); return…
ntu
  • 449
  • 4
  • 4
43
votes
2 answers

Tail Call Optimisation in Java

As of Java 8, Java does not provide Tail-Call Optimization (TCO). On researching about it, I came to know the reason which is: In JDK classes [...] there are a number of security sensitive methods that rely on counting stack frames between JDK…
Rishabh Agarwal
  • 1,988
  • 1
  • 16
  • 33