title: gcc undefined reference to gd functions
body: <p>I'm trying to compile a program, but I get the following error when I run <code>make install</code>. </p>
  
  <pre><code>gcc -fPIC -O3 -g -O2 -o treeviewer -L/usr/include -lm -lpng -ljpeg -lgd treeviewer.o tree.o fileio.o tree.o: 
  In function `drawImage':
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:587: undefined reference to `gdFontMediumBold'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:587: undefined reference to `gdImageString'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:602: undefined reference to `gdImageLine'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:610: undefined reference to `gdImageLine'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:620: undefined reference to `gdImageFilledRectangle'
  tree.o: In function `TreeToImage':
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:477: undefined reference to `gdFontMediumBold'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:526: undefined reference to `gdImageCreate'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:527: undefined reference to `gdImageColorAllocate'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:528: undefined reference to `gdImageColorAllocate'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:529: undefined reference to `gdImageColorAllocate'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:530: undefined reference to `gdImageColorAllocate'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:531: undefined reference to `gdImageColorAllocate'
  tree.o:/home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:532: more undefined references to `gdImageColorAllocate' follow
  tree.o: In function `TreeToImage':
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:548: undefined reference to `gdImagePng'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:552: undefined reference to `gdImageDestroy'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:543: undefined reference to `gdImageJpeg'
  tree.o: In function `printTreeInfo':
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:642: undefined reference to `gdFontMediumBold'
  tree.o: In function `drawImage':
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:627: undefined reference to `gdImageRectangle'
  /home/localadmin/codehop-dev/i-codehop/treeviewer/tree.c:624: undefined reference to `gdImageFilledRectangle'
  collect2: error: ld returned 1 exit status
  make: *** [treeviewer] Error 1
  </code></pre>
  
  <p>I have installed the <code>libgd</code> using the commmand <code>sudo apt-get -y install libgd2-xpm-dev build-essential</code>. The folder <code>/usr/include</code> has the file <code>gd.h</code>. Could anyone tell me what am I missing? Thanks in advance.</p>