title: How to compile Apache Avro C++ example
body: <p>Probably a newbie mistake, but can anyone please tell me what I'm doing wrong here?<br>
  Any help is much appreciated.</p>
  
  <p>I wrote this simple Makefile:</p>
  
  <pre><code>CC=g++
  INC=-I/usr/local/avro-cpp-1.7.2 -I/usr/local/boost_1_53_0
  
  cpx : generated.cc
          $(CC) -o cpx generated.cc $(INC)
  </code></pre>
  
  <p>Which generates these the errors:</p>
  
  <pre><code>g++ -o cpx generated.cc -I/usr/local/avro-cpp-1.7.2 -I/usr/local/boost_1_53_0
  /tmp/ccYymUVo.o: In function `main':
  generated.cc:(.text+0x84): undefined reference to `avro::memoryOutputStream(unsigned long)'
  generated.cc:(.text+0xb0): undefined reference to `avro::binaryEncoder()'
  generated.cc:(.text+0x11e): undefined reference to `avro::memoryInputStream(avro::OutputStream const&amp;)'
  generated.cc:(.text+0x150): undefined reference to `avro::binaryDecoder()'
  collect2: ld returned 1 exit status
  make: *** [cpx] Error 1
  </code></pre>
  
  <p>Here's the source as supplied in the Avro examples directory:</p>
  
  <pre><code>#############################
  # cpx.hh
  #############################
  #ifndef CPX_HH_1278398428__H_
  #define CPX_HH_1278398428__H_
  
  #include "boost/any.hpp"
  #include "avro/Specific.hh"
  #include "avro/Encoder.hh"
  #include "avro/Decoder.hh"
  
  namespace c {
  struct cpx {
      double re;
      double im;
  };
  
  }
  namespace avro {
  template&lt;&gt; struct codec_traits&lt;c::cpx&gt; {
      static void encode(Encoder&amp; e, const c::cpx&amp; v) {
          avro::encode(e, v.re);
          avro::encode(e, v.im);
      }
      static void decode(Decoder&amp; d, c::cpx&amp; v) {
          avro::decode(d, v.re);
          avro::decode(d, v.im);
      }
  };
  
  }
  #endif
  </code></pre>
  
  <p>and</p>
  
  <pre><code>#############################
  # generated.cc
  #############################
  #include "cpx.hh"
  #include "avro/Encoder.hh"
  #include "avro/Decoder.hh"
  
  int
  main()
  {
      std::auto_ptr&lt;avro::OutputStream&gt; out = avro::memoryOutputStream();
      avro::EncoderPtr e = avro::binaryEncoder();
      e-&gt;init(*out);
      c::cpx c1;
      c1.re = 1.0;
      c1.im = 2.13;
      avro::encode(*e, c1);
  
      std::auto_ptr&lt;avro::InputStream&gt; in = avro::memoryInputStream(*out);
      avro::DecoderPtr d = avro::binaryDecoder();
      d-&gt;init(*in);
  
      c::cpx c2;
      avro::decode(*d, c2);
      std::cout &lt;&lt; '(' &lt;&lt; c2.re &lt;&lt; ", " &lt;&lt; c2.im &lt;&lt; ')' &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>Thanks.</p>