Avoiding DuplicateDefinitionException
Is it possible to avoid following exception?: ctypeslib.codegen.handler.DuplicateDefinitionException: 'register: struct_mystruct_t already existed: struct_mystruct_t'
I am defining a name (myhandle) for an internal structure (mystruct_t), which is defined in an internal header file but hidden from API (opaque pointer): typedef struct mystruct_t myhandle;
When this header file is included in multiple places and they are fed to clang2py, it stops with above exception. Is there a way to handle this without error?
test_types.h
#pragma once
typedef struct mystruct_t myhandle;
test.h
#pragma once
#include "test_types.h"
myhandle* create_myhandle();
int use_myhandle(myhandle *handle);
int delete_myhandle(myhandle *handle);
test2.h
#pragma once
#include "test_types.h"
int use_myhandle2(myhandle *handle);
clang2py command
clang2py test.h test2.h test_types.h
This is what I could whip up quickly. Exception can be avoided here, if I change the order of header files given to clang2py (give test_types.h first) but in my environment changing order of the given header files doesn't remove the exception. Only if I remove explicitly the _types.h header (which contain type definition for the handle), exception goes away but then naturally not all types/structures defined in _types.h header file don't get generated.