I was trying to get the C++ cython example described in the docs (http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html) to build in Sage 4.8, but I'm getting some errors I don't understand. I created a separate development branch called "sage-c_extensions", added extension lines
Extension('sage.quadratic_forms.rectangle',
sources = ['sage/quadratic_forms/rectangle/rectangle.pyx',
'sage/quadratic_forms/rectangle/Rectangle.cpp'],
language = "c++"),
in the file sage-c_extensions/sage/module_list.py, copied the Rectangle.h and Rectangle.cpp files from the tutorial into a new folder sage-c_extensions/sage/quadratic_forms/rectangle/, and created a rectangle.pyx file in that folder with contents
cdef extern from "Rectangle.h" namespace "shapes":cdef cppclass Rectangle:Rectangle(int, int, int, int)int x0, y0, x1, y1int getLength()int getHeight()int getArea()void move(int, int)cdef class PyRectangle:cdef Rectangle *thisptr # hold a C++ instance which we're wrappingdef __cinit__(self, int x0, int y0, int x1, int y1):self.thisptr = new Rectangle(x0, y0, x1, y1)def __dealloc__(self):del self.thisptrdef getLength(self):return self.thisptr.getLength()def getHeight(self):return self.thisptr.getHeight()def getArea(self):return self.thisptr.getArea()def move(self, dx, dy):self.thisptr.move(dx, dy)
When I run "./sage -br c_extensions" I get the error message
Updating Cython code....Building modified file sage/quadratic_forms/rectangle/rectangle.pyx.Executing 1 command (using 1 thread)python `which cython` --cplus --old-style-globals --disable-function-redefinition --embed-positions --directive cdivision=True,autotestdict=False,fast_getattr=True -I/Users/jonhanke/Dropbox/SAGE/sage-4.8/devel/sage-c_extensions -o sage/quadratic_forms/rectangle/rectangle.cpp sage/quadratic_forms/rectangle/rectangle.pyxsage/quadratic_forms/rectangle/rectangle.pyx --> /Users/jonhanke/Dropbox/SAGE/sage-4.8/local/lib/python2.6/site-packages//sage/quadratic_forms/rectangle/rectangle.pyxTime to execute 1 command: 16.2038929462 secondsFinished compiling Cython code (time = 31.5890960693 seconds)running installrunning buildrunning build_pyrunning build_extbuilding 'sage.quadratic_forms.rectangle' extensionExecuting 1 command (using 1 thread)gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/jonhanke/Dropbox/SAGE/sage-4.8/local/include -I/Users/jonhanke/Dropbox/SAGE/sage-4.8/local/include/csage -I/Users/jonhanke/Dropbox/SAGE/sage-4.8/devel/sage/sage/ext -I/Users/jonhanke/Dropbox/SAGE/sage-4.8/local/include/python2.6 -c sage/quadratic_forms/rectangle/rectangle.cpp -o build/temp.macosx-10.6-i386-2.6/sage/quadratic_forms/rectangle/rectangle.o -wcc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/jonhanke/Dropbox/SAGE/sage-4.8/local/include -I/Users/jonhanke/Dropbox/SAGE/sage-4.8/local/include/csage -I/Users/jonhanke/Dropbox/SAGE/sage-4.8/devel/sage/sage/ext -I/Users/jonhanke/Dropbox/SAGE/sage-4.8/local/include/python2.6 -c sage/quadratic_forms/rectangle/Rectangle.cpp -o build/temp.macosx-10.6-i386-2.6/sage/quadratic_forms/rectangle/Rectangle.o -wcc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++g++ -L/Users/jonhanke/Dropbox/SAGE/sage-4.8/local/lib -bundle -undefined dynamic_lookup build/temp.macosx-10.6-i386-2.6/sage/quadratic_forms/rectangle/rectangle.o build/temp.macosx-10.6-i386-2.6/sage/quadratic_forms/rectangle/Rectangle.o -L/Users/jonhanke/Dropbox/SAGE/sage-4.8/local/lib -lcsage -lstdc++ -lntl -o build/lib.macosx-10.6-i386-2.6/sage/quadratic_forms/rectangle.sold: duplicate symbol _initrectangle in build/temp.macosx-10.6-i386-2.6/sage/quadratic_forms/rectangle/Rectangle.o and build/temp.macosx-10.6-i386-2.6/sage/quadratic_forms/rectangle/rectangle.ocollect2: ld returned 1 exit statuserror: command 'g++' failed with exit status 1sage: There was an error installing modified sage library code.
Any comments are appreciated. Also, it seems that Cython converts the Rectangle.cpp file to a "cythoned" file rectangle.cpp, deleting the original file in the process. Is this normal/ok?
Thanks,
-Jon
=)
-- To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to sage-devel+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
0 ความคิดเห็น:
แสดงความคิดเห็น