I need to link 2 libraries. The first library requires a header file in which:
typedef int TYPE
The second library requires a header file in which:
typedef struct type TYPE
Obviously linking them results in a violation of the One Definition Rule (ODR). The obvious solution here is to rename one of the types. However, this will require me to change that in hundreds of files too, which I'm trying to avoid because it will make all of our projects inconsistent. Is there any other way to overcome this issue?
If library A has the header file
header_a.h
and library B has header fileheader_b.h
you can do something like this as a workaround in source code forms that have to include both:This causes the declarations
to appear as
This should work fine as type information is not present in object file. Nonetheless, the header files from libraries A and B might do weird stuff with macros that break with these definitions, so you should check for that before.