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?
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.
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.
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.
A compiler generates object code files (machine language) from source code. A linker combines these object code files into an executable.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With