I've developed a custom C++ linux library to control a device through my driver. The library controls the flow to correctly use the device and I'd like my users to be able to call the "lib/API" from C and C++ app.
Basically the library is just a class containing public and private/protected variables and methods.
The users should be able to call my library from C and C++ application.
I'd like to hide all those private/protected variables and methods from the header.
What's the best practice for my need?
Is there a tool out there being able to generate/export automatically:
- a C header file for the user to develop a C application
- Basically a
struct
instead ofclass
and functions with thestruct*
instead of method
- Basically a
- a C++ header file exposing only the public variables and methods
- the class definition will be different then I'm not sure it works
- a C header file for the user to develop a C application
Long time ago, I received a shared library with a C header file with all the functions that looked like it was developed originally in C++.
Edit:
- Is there a way to have a C header that links to C++ class?
C++ header:
class foo
{
public:
int foo(bar *bar);
private:
foo *m_foo;
};
C header equivalent to the C++ header:
struct foo;
int foo_foo(foo* foo, bar *bar);