Using C++ typedef in cython

25 views
Skip to first unread message

Andrew Nelson

unread,
Dec 10, 2024, 4:59:02 PM12/10/24
to cython-users
How do I declare/use a C++ typedef in cython? 
In C++ library code that I want to use:

```
// myfunc.h
// implementation is in myfunc.cpp
typedef std::complex<double> Cplx;
void func(int len, Cplx *val);
```

Now I want to use `func` from cython. In the cython code:

```
cdef extern from "myfunc.h" nogil:
    void func(int len, Cplx *val)
```

But I need to define what `Cplx` is in the cython file, and it's not clear to me how to do that. I'd rather not have to change the original library file.

da-woods

unread,
Dec 11, 2024, 3:24:13 AM12/11/24
to cython...@googlegroups.com
ctypedef.

e.g.

cdef extern from "myfunc.h" nogil:
   ctypedef libcpp.complex.complex[double] Cplx
   ...

(assuming you've cimported libcpp.complex)
--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/0e761001-1e2b-4f71-aa6d-968c8cc0949bn%40googlegroups.com.


Reply all
Reply to author
Forward
0 new messages