What is a wrapper, and how do I make one?

Quite often I’ll come across addons that are described as being ‘wrappers’ of another library that makes them usable in OpenFrameworks.

There’s a library I’d like to use, it’s written in C++, but there’s currently no addon for it. How might I go about writing one of these wrappers? Can anyone point me to a good article or tutorial to start poking around? Perhaps an overview of fundamentals, or even better a step-by-step walkthrough of creating a wrapper?

There aren’t any tutorials that I know of, but a wrapper usually involves compiling the library to make it easier for openFrameworks users to use, then creating any bridges to make it easier to use the library with openFrameworks types.

For instance, in ofxDlib, I wrote a set of templated types that makes our ofPixels compatible with dlib’s native image type.


Typically you start with a template like this:

What library are you trying to wrap?

Thanks for that response, and for providing examples. I’m going to have a poke around and see what I can do. It’s for the SDK over here: https://developer.ultrahaptics.com/

I’m coming back to this after 6 months, and just wanted to contribute some things I found helpful:

  • I was trying to run before I could walk. Meaning, I was thinking about writing a wrapper because that’s the method I thought you had to use in order to make use of external libraries. Turns out you can just integrate them using that library’s API. Point 4 in this reply really helped: Are there good resources on how to use C++ libraries (in openFrameworks)?
    I now have my library working in an app thanks to that.

  • The term ‘wrapper’ when used in an OpenFrameworks discussion is kind of a catch-all for a few different ways of making an external library available via an ofxAddOn style interface. Having looked at a lot of different hardware interface addons, it looks like I should base my wrapper on the ‘Adapter’ design pattern: https://sourcemaking.com/design_patterns/adapter/cpp/1

I hope to update as I go. Cheers.