Node:undefined reference to..., Next:unterminated string or character constant, Previous:parse error at..., Up:Compile-time errors
undefined reference to...
This error is often generated because you have typed the name of
a function or variable incorrectly. For example, the following code:
#include <stdio.h> void print_hello() { printf ("Hello!\n"); } /* To shorten example, not using argp */ int main() { Print_hello(); return 0; }
generates the following rather forbidding error:
/tmp/cc9KXhmV.o: In function `main': /tmp/cc9KXhmV.o(.text+0x1f): undefined reference to `Print_hello' collect2: ld returned 1 exit status
The answer, however, is very simple. C is case-sensitive. The
main
function calls the function Print_hello
(with a
capital P
), but the correct name of the function is
print_hello
(with a lower-case p
). The linker
could not find a function with the name Print_hello
.