# How to call the C++ class methods in library from jitted function, just as numpy?

**URL:** <https://numba.discourse.group/t/how-to-call-the-c-class-methods-in-library-from-jitted-function-just-as-numpy/2684>\
**Category:** Support: How do I do ...?\
**Created:** [August 13, 2024, 8:21am UTC](https://numba.discourse.group/t/how-to-call-the-c-class-methods-in-library-from-jitted-function-just-as-numpy/2684 "2024-08-13T08:21:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kane](https://avatars.discourse-cdn.com/v4/letter/k/76d3ee/32.png) [@Kane](https://numba.discourse.group/u/Kane)\
**Post date:** [August 13, 2024, 8:21am UTC](https://numba.discourse.group/t/how-to-call-the-c-class-methods-in-library-from-jitted-function-just-as-numpy/2684/1 "2024-08-13T08:21:30Z")

</div>

Hi~  
My goal is to call the C++ class methods in a library from jitted functions(in nopython mode). Currently the doc of numba provides ways to handle C struct([here](https://numba.readthedocs.io/en/stable/user/cfunc.html#handling-c-structures)) , and to call the C function in C library([here](https://numba.readthedocs.io/en/stable/user/cfunc.html#calling-c-code-from-numba)).

I want to move a little forward. Are there any ways to use the C++ class in jitted funcion, just like we use numpy? The python API of numpy is in a object-orientated stytle. I wonder can I program a library which can be used as numpy. In other word, what is the standard the numpy complies with, which makes it understandable by numba in nopython mode?

---

<div class="post-metadata">

**Author:** ![gmarkall](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/gmarkall/32/42_2.png) [@gmarkall](https://numba.discourse.group/u/gmarkall)\
**Post date:** [August 13, 2024, 8:45am UTC](https://numba.discourse.group/t/how-to-call-the-c-class-methods-in-library-from-jitted-function-just-as-numpy/2684/2 "2024-08-13T08:45:32Z")

</div>

Have you already looked at [cppyy’s Numba support](https://cppyy.readthedocs.io/en/latest/numba.html)? It looks like it might fit your needs - what do you think?

---

<div class="post-metadata">

**Author:** ![Kane](https://avatars.discourse-cdn.com/v4/letter/k/76d3ee/32.png) [@Kane](https://numba.discourse.group/u/Kane)\
**Post date:** [August 13, 2024, 10:49am UTC](https://numba.discourse.group/t/how-to-call-the-c-class-methods-in-library-from-jitted-function-just-as-numpy/2684/3 "2024-08-13T10:49:36Z")

</div>

Hi Markall！  
I think it is not what I need~  
I want the cfunc functions to manipulate an object defined in dynamic library, just like manipulating the numpy ndarray.

---

<div class="post-metadata">

**Author:** ![gmarkall](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/gmarkall/32/42_2.png) [@gmarkall](https://numba.discourse.group/u/gmarkall)\
**Post date:** [August 13, 2024, 11:17am UTC](https://numba.discourse.group/t/how-to-call-the-c-class-methods-in-library-from-jitted-function-just-as-numpy/2684/4 "2024-08-13T11:17:51Z")

</div>

Are the objects POD types?

---

<div class="post-metadata">

**Author:** ![Kane](https://avatars.discourse-cdn.com/v4/letter/k/76d3ee/32.png) [@Kane](https://numba.discourse.group/u/Kane)\
**Post date:** [August 13, 2024, 12:22pm UTC](https://numba.discourse.group/t/how-to-call-the-c-class-methods-in-library-from-jitted-function-just-as-numpy/2684/5 "2024-08-13T12:22:51Z")

</div>

Not only POD~  
I think I should make myself more clear. I hope to progam some C++ extentions in the form of dynamic library. These C++ extentions may define functions, classes. By exposing symbols, these extensions can be imported and used in python.

Although there are several methods to write C++ extensions which can used by python (for example with help with pybind11), these methods are not friendly to numba. I wonder if it is possible to make the C++ dynamic library understanable to numba?

---

<div class="post-metadata">

**Author:** ![Kane](https://avatars.discourse-cdn.com/v4/letter/k/76d3ee/32.png) [@Kane](https://numba.discourse.group/u/Kane)\
**Post date:** [August 15, 2024, 1:07am UTC](https://numba.discourse.group/t/how-to-call-the-c-class-methods-in-library-from-jitted-function-just-as-numpy/2684/6 "2024-08-15T01:07:49Z")

</div>

I probally find a solution inspired by [this](https://labs.quansight.org/blog/2021/10/cxx-numba-interoperability). In this article, it provides a tool to expose C++ function, and static member function to numba. But currently I have not extended it to class member function.

The mechanism is here: It uses a Cstyle function(extern “C”) to get the C++ function address. In python, it uses the [“rbc” package](https://github.com/heavyai/rbc) to convert the address to a ctypes function(with argtypes and resypes). I think I can use this mechanism I can ecapsulate a C++ class to python. However it is not a direct way.

I still do not know how the numba can recogonise numpy.if I know, I can mimick the numpy to program the C++ extension
