1

Context

I am writing a program in rust which links into a c++ library, however rust is unable to generate bindings to virtual functions. While there are likely better approaches, the most straightforward solution is to write an extra layer of abstraction which I can generate bindings to.

Issue

My c++ abilities are somewhat lacking so I was wondering if there is a library which can quickly generate wrappers to the original functions.

What I have

  • Lots of header files which each contain a class with a create() -> ptr function as well as roughly ~40 virtual functions.
  • A .so corresponding to the header. I do not have access to the original source.

Header sample

class tPower
{
public:
   tPower(){}
   virtual ~tPower(){}

   virtual tSystemInterface* getSystemInterface() = 0;
   static tPower* create(tRioStatusCode *status);

   virtual void writeDisable(tDisable value, tRioStatusCode *status) = 0;
   virtual void writeDisable_User3V3(bool value, tRioStatusCode *status) = 0;
   virtual void writeDisable_User5V(bool value, tRioStatusCode *status) = 0;
   virtual void writeDisable_User6V(bool value, tRioStatusCode *status) = 0;
   virtual tDisable readDisable(tRioStatusCode *status) = 0;
   virtual bool readDisable_User3V3(tRioStatusCode *status) = 0;
   virtual bool readDisable_User5V(tRioStatusCode *status) = 0;
   virtual bool readDisable_User6V(tRioStatusCode *status) = 0;

   // This goes on for another 30 or so functions plus the typedef for types referenced.
   // There are no generics or any other language features used in these files.


How would I go about generating these wrappers or what more effective approach could I use to solve this issue?



Edit: I did not tag this question with rust since this has already come up a few times and the conclusion was almost always to write a wrapper in c++. My question is more relating to how I might be able to automate that process so I don't have to spend a few hours writing repetitive code.

Locke
  • 7,626
  • 2
  • 21
  • 41
  • 1
    may be using a shell/perl/python script or a C program? I don't know how do you get those pure virtual function names in the first place. – Sameer Naik Feb 28 '19 at 06:21

0 Answers0