Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler error vs linker error? [closed]

Just reading Effective C++ and he mentions several times "linker error", as opposed to compiler error.

What constitutes a "linker error" and how do they differ from "compiler errors"? Are the rules/explanations based around a set of categories to logically remember this?

like image 373
user997112 Avatar asked Feb 18 '13 23:02

user997112


People also ask

What is a linker error?

Linker errors occur when the linker is trying to put all the pieces of a program together to create an executable, and one or more pieces are missing. Typically, this can happen when an object file or libraries can't be found by the linker.

What is the compiler error?

Compilation error refers to a state when a compiler fails to compile a piece of computer program source code, either due to errors in the code, or, more unusually, due to errors in the compiler itself. A compilation error message often helps programmers debugging the source code.

Is syntax error and compiler error same?

Syntax errors: Errors that occur when you violate the rules of writing C/C++ syntax are known as syntax errors. This compiler error indicates something that must be fixed before the code can be compiled. All these errors are detected by compiler and thus are known as compile-time errors.

What is a linker vs compiler?

A compiler generates object code files (machine language) from source code. A linker combines these object code files into an executable.


2 Answers

Compiler errors mean the compiler could not translate the source code you provided into object code. It usually means you have a syntactic or semantic error in your own program that you have to resolve before your program exhibits the behavior you're intending it to have.

Linker errors mean the linker could not build an executable program from the object code you provided. It usually means your program does not properly interface with its own dependencies or with the outside world (e.g. external libraries).

like image 79
Frédéric Hamidi Avatar answered Oct 11 '22 09:10

Frédéric Hamidi


Compiler errors are the class of errors related to the semantics of your code during compilation i.e. the process of conversion of sources to object files. Here, you may have defined certain symbols (for example pthread_create) which are assumed to be available.

Linker errors are errors encountered when these dependencies are verified during the creation of a final object file. Going with the example above, for the creation of the executable, you need the definition of pthread_create which if not found will give a linker error.

like image 22
Ganesh Avatar answered Oct 11 '22 09:10

Ganesh