Building C interfaces for classes in OpenCASCADE

I am trying to build C interfaces for classes in OpenCASCADE for use in Pharo (https://pharo.org/) for a school project. The reason for using the C interfaces is because Pharo can only communicate with other languages via uFFI (unified Foreign Function Interface) (https://books.pharo.org/booklet-uffi/), and uFFI can only call functions via a C-style shared library file ie .dll .so and .lib. I would like to know whether this is possible, and if it is possible how should I start creating the C interface.

gkv311 n's picture

Wrapping a couple of functions (introducing your own API, written in C++, but exported in C-style function set) should be fine as long as you need only small number of features to be exposed.

Otherwise, it would be better looking into some automated wrapping tools like SWIG. Have no idea if there any tool for Pharo, though.

JIA JIE Ee's picture

Thanks for your reply, but I am having problems with compiling the files with a C wrapper on Visual Studio Community 2022 (17.5.1). I am still struggling with CMake to make it a reasonable replacement for having everything running in VS. One class I am trying to use is BRepPrimAPI_MakeBox.hxx. Any help with an example is greatly appreciated.

Dmitrii Pasukhin's picture

Hello,

To create a C wrapper for the OCCT libraries on Windows using Visual Studio 2022, you can follow these steps:

  1. First, clone and install (or just dowload from site)  the Open CASCADE Technology (OCCT) libraries on your computer.

  2. Create a new C++ project in Visual Studio 2022.

  3. Link the necessary OCCT libraries to your project. You can do this by adding the library directories and header directories to your project's settings.

  4. Create a set of static C functions that will act as the wrapper for the OCCT functionality you require. These functions should have a C-compatible interface and should internally use the C++ OCCT functions.

  5. Compile your project as a dynamic-link library (DLL) or a static library (LIB), depending on your requirements.

  6. In your main C project, link to the newly created DLL or LIB and call the static C functions you defined earlier.

This approach is convenient when you need to use a limited subset of OCCT functionality. However, if you need to wrap the entire OCCT library, it may be more challenging and time-consuming.

Best regards, Dmitrii.