Cython: operation only allowed in c++

686 views
Skip to first unread message

Nathann Cohen

unread,
Oct 1, 2015, 3:17:05 AM10/1/15
to Sage devel
Hello everybody,

Sorry to bug you with that, but I am getting an error when compiling a
Cython c++ file, and I can't figure out what I did wrong:

sage: cat a.pyx
#clang C++
from libcpp.vector cimport vector
cdef vector[int] * v = new vector[int](4)

sage: %runfile a.pyx
...
RuntimeError: Error converting ./a.pyx to C:
...
cdef vector[int] * v = new vector[int](4)
^
------------------------------------------------------------
_home_ncohen_lexbfs_a_pyx_10.pyx:8:27: Operation only allowed in c++

What bothers me is that the arrow points toward the keyword 'new', and
that the error says 'error converting to C', despite explicitly saying
that this should be a C++ file.

Furthermore, I activated some verbosity in misc/cython.pyx and it
seems that C++ is detected allright, sooo ... O_o

Thanks for any kind of enlightenment O_o

Nathann

P.S. I added the line "cdef vector[int] * v = new vector[int](4)" in a
.pyx file of Sage's source code declared as lang=C++ in
modules_list.py, and it compiled fine.

Jeroen Demeyer

unread,
Oct 1, 2015, 3:43:14 AM10/1/15
to sage-...@googlegroups.com
Well, this whole cython() thing is really a mess, that's all I can say...

Nathann Cohen

unread,
Oct 1, 2015, 4:25:35 AM10/1/15
to Sage devel
> Well, this whole cython() thing is really a mess, that's all I can say...

Thanks. If not for your message, I would still be fighting with my file.

I fixed it at #19325, which just adds a --cplus flag when necessary.
But I wonder why it seems that the setup.py file is not used O_o

Nathann

http://trac.sagemath.org/ticket/19325

Jeroen Demeyer

unread,
Oct 1, 2015, 4:35:48 AM10/1/15
to sage-...@googlegroups.com
On 2015-10-01 10:25, Nathann Cohen wrote:
> But I wonder why it seems that the setup.py file is not used

Note that there is no mention of Cython at all in setup.py
It's used only to compile .c -> .so

Of course, it should (and easily could) be used to compile also .pyx ->
.c(pp) which would solve many problems.

Reply all
Reply to author
Forward
0 new messages