Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - undefined reference to...

Node:undefined reference to..., Next:, 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.

 
 
  Published under free license. Design by Interspire