Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate C wrapper from C++?

Tags:

I want to generate C wrappers from C++ libraries. There are tutorials on how to do it by hand:

  • http://dsc.sun.com/solaris/articles/mixing.html
  • http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html

But it is too much of a manual labor.

For example, for this:

struct RtAudio {     virtual DeviceInfo const& f() {...}     class DeviceInfo {         virtual void g() { ... }     };     ... }; 

I need to write:

struct RtAudioC {     RtAudio x; }; struct DeviceInfo {     RtAudio::DeviceInfo x; }; extern "C" {     RtAudioC* newRtAudio() {          return new RtAudioC;     }     void deleteRtAudio(RtAudioC *p {         delete p;     }     /* do something with RtAudio::f() */     void g(DeviceInfo *p) {         try {             p->x.g();         } catch (SomeError & err) {         }     } } 

Are there tools that can automate this process?

like image 943
numeric Avatar asked Jul 01 '09 04:07

numeric


1 Answers

You can try SWIG, C code generator was last year's GSoC project. AFAIK they haven't merged it to the trunk yet, so you'd have to checkout & build the branch from SVN.

like image 196
Taavi Avatar answered Sep 21 '22 22:09

Taavi