title: How to link C library in Ruby extension
body: <p>I'm building a relatively simple C extension to count pixels in a PNG file using libpng; I built the original version in C and it compiles (and works) fine in Cygwin with the command: </p>
  
  <blockquote>
    <p>gcc -o shadow_counter shadow_counter.c -lpng</p>
  </blockquote>
  
  <p>If I don't include the "-lpng" command it won't compile and kicks out a bunch of errors when trying to read the libpng functions ("undefined reference to `png_sig_cmp' ", etc.)</p>
  
  <p>In order to package it for ruby, I put together the gemspec and files and folders and build it into a gem:</p>
  
  <blockquote>
    <p>gem build shadow_png.gemspec</p>
  </blockquote>
  
  <p>Then I head over to Powershell and install the gem:</p>
  
  <blockquote>
    <p>gem install shadow_png-0.0.1.gem</p>
  </blockquote>
  
  <p>If I leave out the libpng stuff, it installs fine and talks to Ruby the way it's supposed to.  But once I start trying to reference the libpng functions and try to install it, it starts kicking out the SAME errors that I saw above (undefined reference to `png_sig_cmp' etc.).  So my theory is that somehow the linking command -lpng isn't included. </p>
  
  <p>How do I include these instructions as part of the process?  Is it something I need to add to the gemspec?  Or the command to build the gem?  Or does it have to happen in the gem installation? </p>
  
  <p>Thanks!</p>