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

Can I use Qt without qmake or Qt Creator?

I want to program using Qt, but I don't want to use special compilers or IDE such as Qt Creator and qmake. I want to write with Kate and compile with g++. Can I compile a program that uses Qt with g++? How do I compile it with g++?
Squall
  • 4,344
  • 7
  • 37
  • 46
77
votes
5 answers

IUnityContainer.Resolve throws error claiming it cannot be used with type parameters

Yesterday I've implemented the code: CustomerProductManager productsManager = container.Resolve(); It was compilable and working. Today (probably I've modified something) I am constantly getting the error: The non-generic…
Budda
  • 18,015
  • 33
  • 124
  • 206
76
votes
10 answers

How to speed up g++ compile time (when using a lot of templates)

This question is perhaps somehow odd, but how can I speed up g++ compile time? My C++ code heavily uses boost and templates. I already moved as much as possible out of the headers files and use the -j option, but still it takes quite a while to…
Danvil
  • 22,240
  • 19
  • 65
  • 88
75
votes
11 answers

Gradle "Entry .classpath is a duplicate but no duplicate handling strategy has been set"

I'm trying to build a gradle project but, when I try $ gradle build I get the following output: Starting a Gradle Daemon (subsequent builds will be faster) > Task :jar FAILED FAILURE: Build failed with an exception. * What went wrong: Execution…
136
  • 1,083
  • 1
  • 7
  • 14
75
votes
10 answers

Why not concatenate C source files before compilation?

I come from a scripting background and the preprocessor in C has always seemed ugly to me. None the less I have embraced it as I learn to write small C programs. I am only really using the preprocessor for including the standard libraries and header…
user3420382
74
votes
13 answers

Why does not the Application_Start() event fire when I debug my ASP.NET MVC app?

I currently have the following routines in my Global.asax.cs file: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", …
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
74
votes
7 answers

Why do you need to recompile C/C++ for each OS?

This is more of a theoretical question than anything. I'm a Comp sci major with a huge interest in low level programming. I love finding out how things work under the hood. My specialization is compiler design. Anyway, as I'm working on my first…
Nassim Assaf
  • 773
  • 5
  • 5
74
votes
3 answers

Compiler stops optimizing unused string away when adding characters

I am curious why the following piece of code: #include int main() { std::string a = "ABCDEFGHIJKLMNO"; } when compiled with -O3 yields the following code: main: # @main xor eax, eax ret (I…
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
74
votes
11 answers

Scala double definition (2 methods have the same type erasure)

I wrote this in scala and it won't compile: class TestDoubleDef{ def foo(p:List[String]) = {} def foo(p:List[Int]) = {} } the compiler notify: [error] double definition: [error] method foo:(List[String])Unit and [error] method…
Jérôme
  • 990
  • 1
  • 9
  • 14
74
votes
9 answers

How to recompile with -fPIC

I was trying to reinstall my ffmpeg, following this guide, on my ARM Ubuntu machine. Unfortunately, when I compile a program which uses this lib I get the following failure: /usr/bin/ld: /usr/local/lib/libavcodec.a(amrnbdec.o): relocation…
user1455085
  • 915
  • 1
  • 6
  • 10
73
votes
5 answers

How do header and source files in C work?

I've perused the possible duplicates, however none of the answers there are sinking in. tl;dr: How are source and header files related in C? Do projects sort out declaration/definition dependencies implicitly at build time? I'm trying to understand…
Dan Lugg
  • 20,192
  • 19
  • 110
  • 174
73
votes
5 answers

Is it possible to compile a single C# code file with the .NET Core Roslyn compiler?

In old .NET we used to be able to run the csc compiler to compile a single .cs file or several files. With .NET Core we have dotnet build that insists on having a proper project file. Is there a stand-alone command line compiler that would allow to…
Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158
73
votes
7 answers

How to compile/install node.js(could not configure a cxx compiler!) (Ubuntu).

How can I compile/install node.js on Ubuntu? It failed with an error about cxx compiler.
Alfred
  • 60,935
  • 33
  • 147
  • 186
72
votes
14 answers

How to decrease build times / speed up compile time in Xcode?

What strategies can be used in general to decrease build times for any Xcode project? I'm mostly interested in Xcode specific strategies. I'm doing iPhone development using Xcode, and my project is slowly getting bigger and bigger. I find the…
Brad Parks
  • 66,836
  • 64
  • 257
  • 336
70
votes
14 answers

Do programming language compilers first translate to assembly or directly to machine code?

I'm primarily interested in popular and widely used compilers, such as gcc. But if things are done differently with different compilers, I'd like to know that, too. Taking gcc as an example, does it compile a short program written in C directly to…
Mr Mister