I need to make a wrapper for a C header, in such a way that none of the functions from that header can be visible outside this wrapper.
The first thing that came to my mind was to use a namespace in the include
, but it didn't work, as expected, due to C++ mangling, like so:
namespace wrap {
extern "C" {
#include<a/b/c_header.h>
}};
This will give me errors like: cannot convert 'wrap::some_type*' to 'some_type*' for argument # from __some_inner_function
, which I find very annoying because both types are actually the same.
This header has hundreds of functions which I'm currently using in my code, so wrapping one by one might not be feasible, in particular because it is not something so trivial to be solved with a few sed
's.
I'm afraid that this has no solution, and that I would simply have to accept that all functions from those headers will have global scope.
I wondered if I could make some fancy macros to help me on this, but I couldn't come up with anything.