1

I have two types "Company" and "User" both including a common type "Address", and am trying to generate cpp header files. I tried multiple ways, but I end up having "Address" struct being multiply defined in two different header files. Can avrogencpp generate one header for each type instead of having everything in one single file?

This is as far as I could go:

1) Created sample.avdl

@namespace("test")
protocol Simple {
  record Address {
    string street;
    string state;
    string zip;
  }
  record Company {
    string name;
    Address address;
  }
  record Employee {
    string firstName;
    string lastName;
    Address address;
  }
}

2) Used avro-tools to generate schema files: avro-tools idl2schemata sample.avdl

3) Used avrogencpp to generate headers:

avrogencpp -i Address.avsc -o address.h
avrogencpp -i Employee.avsc -o employee.h
avrogencpp -i Company.avsc -o company.h

Now, the problem is both employee.h and company.h multiply define struct Address and hence unable to compile together.

1 Answers1

1

Neither is avrogencpp a smart program, nor is the entire C++ API for Avro well conceived. Some post-processing hackery is almost always needed for sane code.

In this case, your best shot is to edit the generated company.h and employee.h files: remove the redundant code (the Address and codec_traits<Address> structs) and insert

#include "address.h"

among the includes at the top. (In fact, you could replace the generated includes with just this one, as every generated header file has that same set of includes.)

arayq2
  • 2,502
  • 17
  • 21