title: How to generate a C++ header with Apache Avro (python script)
body: <p>I am interested in generating a C++ header using Apache Avro's code generation tool (i.e. the python script). <a href="http://avro.apache.org/docs/1.4.0/api/cpp/html/index.html" rel="nofollow">According to the documentation</a> it should be fairly easy to do, but I don't usually use python, so things look kinda strange to me.</p>
  
  <p><strong>The instructions state:</strong></p>
  
  <p>To generate the code is a two step process:</p>
  
  <pre><code>precompile &lt; imaginary &gt; imaginary.flat
  </code></pre>
  
  <p>The precompile step converts the schema into an intermediate format that is used by the code generator. This intermediate file is just a text-based representation of the schema, flattened by a depth-first-traverse of the tree structure of the schema types.</p>
  
  <pre><code>python scripts/gen-cppcode.py --input=example.flat --output=example.hh –-namespace=Math
  </code></pre>
  
  <p>This tells the code generator to read your flattened schema as its input, and generate a C++ header file in example.hh. The optional argument namespace will put the objects in that namespace...</p>
  
  <h2>My Issue (no, I can't see a doctor or use a cream for it):</h2>
  
  <p>I don't see anything that explains in details how to precompile. The documentation makes it seem like if I just type "precompile" in the command prompt and supply the command line arguments, then things would magically work, but precompile is not a valid Windows command. <strong>So what's the proper way to precompile on Windows?</strong> If anybody knows how to do it, then PLEASE let me know!</p>
  
  <p>I also tried to run the <a href="http://svn.apache.org/repos/asf/avro/trunk/lang/c++/scripts/gen-cppcode.py" rel="nofollow">gen-cppcode.py</a> script, but it gets an error in line 316 (which, I suspect, may be happening because I didn't precompile the schema):</p>
  
  <pre><code>def doEnum(args):
      structDef = enumTemplate;
      typename = args[1]
      structDef = structDef.replace('$name$', typename)
      end = False
      symbols = '';
      firstsymbol = '';
      while not end:
          line = getNextLine()
          if line[0] == 'end': end = True
          elif line[0] == 'name':
              if symbols== '' :
                  firstsymbol = line[1]
              else :
                  symbols += ', '
              symbols += line[1]
          else: print "error" // &lt;-- Syntax Error: invalid syntax
      structDef = structDef.replace('$enumsymbols$', symbols);
      structDef = structDef.replace('$firstsymbol$', firstsymbol);
      addStruct(typename, structDef)
      return (typename,typename)
  </code></pre>