Ways to compile C++ code for Grasshopper?


I’m looking for strategies that would enable me to use C++ code in Grasshopper.
I’m not interested in compiling other peoples’ libraries, but I’ve recently started learning C++ and now I want to harness some of this power for my GH projects. Also, I’m a macOS user!!

I have no idea how this could work! Do I need to use Python (or C#) as an intermediary to load some compiled library or header?
On Windows, you compile DLLs, what would be the macOS equivalent?

Any ideas guys? It this even possible for mac users?
Any pointers to where to start are welcome (pun intended). :smiley:


Since GH is implemented as a .NET plug-in you’ll be ending up writing your C++ code as a shared library and then write a wrapper library using P/Invoke.

Note though that on the Mac there is no C++ SDK for Rhino, so you won’t be able to use that. If you write ‘pure’ C++ code then you can do that. If you intend to use the Rhino C++ SDK you’ll be confined to Windows.

Anyway, for getting C++ code into GH the keyword is P/Invoke.

1 Like

If you want to learn a lot about how to go from managed to unmanaged code and vice versa, this is the way to go :wink:

I have had to deal with this in the past, because I wanted to use (already existing) c++ libraries within grasshopper. There I think this aspect becomes really relevant, you don’t want to rewrite the c++ library in c#.

But if you’re creating something from scratch which is specifically intended for use in Grasshopper personally I’d recommend to create that code in C# straight away. You’d have to deal with the syntax anyways when writing those wrapper classes. And it just adds another layer of complexity with that intermediate library (which could also create performance losses).

1 Like

I’d rather stay away from C#. It’s too cool and Microsoft-y for me! :wink:

Hm, that’s a bummer! Why is that?
Seems like I’ll be sticking with openFrameworks and Cinder for some of my creative endeavours.

Anyways, thank you very much for explaining this! Much appreciated.

Got it.

Seems logical, yes.

Noted, but no thanks! :wink:
Thanks for your comment though!

The RhinoCommon SDK is intended to be the cross-platform SDK. Raytraced (RhinoCycles) is integrated through RhinoCommon precisely because of that. And it works on both platforms precisely because of that.

1 Like