Compiler error vs linker error?

Easy Reading Effective C ++ and it mentions "linker error" several times as opposed to compiler error.

What are "linker errors" and how are they different from "compiler errors"? Are rules / explanations based on a set of categories logically memorable?

+3


source to share


3 answers


Compiler errors mean that the compiler was unable to translate the source code provided into object code. This usually means that you have a syntax or semantic error in your own program that you must resolve before your program exhibits the behavior you intend to have.



Linker errors mean that the linker was unable to create an executable program from the object code you provided. This usually means that your program is not communicating correctly with its dependencies or with the outside world (for example, external libraries).

+9


source


Compiler errors are a class of errors related to the semantics of your code at compile time, that is, the process of converting sources to object files. Here you can define certain symbols (for example pthread_create

) that are supposedly available.



Linker errors are errors that are encountered while checking these dependencies during the creation of the final object file. Following the example above, in order to create an executable you need a definition pthread_create

which, if not found, will give a linker error.

+1


source


gcc -c

is compiled and not referenced:

   -c  Compile or assemble the source files, but do not link.  The linking
       stage simply is not done.

      

You can compile the file and then link it with -o

:

$ gcc -c hello.s
$ gcc -o test hello.o 
$ ./test 
Hi World

      

+1


source







All Articles