ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 15 Jun 2011 22:53:06 -0500Call C/C++ Codehttp://ask.sagemath.org/question/8165/call-cc-code/Let's say, I wrote matrix.c which is a C file containing several functions. Can I call any of the functions defined in matrix.c from Sage? What special compilation do I need for matrix.c?Wed, 15 Jun 2011 18:14:22 -0500http://ask.sagemath.org/question/8165/call-cc-code/Answer by Joaquim Puig for <p>Let's say, I wrote matrix.c which is a C file containing several functions. Can I call any of the functions defined in matrix.c from Sage? What special compilation do I need for matrix.c?</p>
http://ask.sagemath.org/question/8165/call-cc-code/?answer=12435#post-id-12435You can use your C/C++ code directly, using the Ctypes library, which is included in SAGE. You can find a nicely documented example on how to call your libraries on Numerical Sage documentation:
[http://www.sagemath.org/doc/numerical_sage/ctypes.html](http://www.sagemath.org/doc/numerical_sage/ctypes.html)
Wed, 15 Jun 2011 22:53:06 -0500http://ask.sagemath.org/question/8165/call-cc-code/?answer=12435#post-id-12435Answer by kcrisman for <p>Let's say, I wrote matrix.c which is a C file containing several functions. Can I call any of the functions defined in matrix.c from Sage? What special compilation do I need for matrix.c?</p>
http://ask.sagemath.org/question/8165/call-cc-code/?answer=12434#post-id-12434Probably you will want to use [Cython](http://cython.org/) to do this - it's a good way to integrate C libraries with Sage (as well as to create C code from within Sage).
You may also want to [search this site for Cython](http://ask.sagemath.org/questions/?query=cython&search=search) for more tips.Wed, 15 Jun 2011 18:56:58 -0500http://ask.sagemath.org/question/8165/call-cc-code/?answer=12434#post-id-12434Comment by DSM for <p>Probably you will want to use <a href="http://cython.org/">Cython</a> to do this - it's a good way to integrate C libraries with Sage (as well as to create C code from within Sage).</p>
<p>You may also want to <a href="http://ask.sagemath.org/questions/?query=cython&search=search">search this site for Cython</a> for more tips.</p>
http://ask.sagemath.org/question/8165/call-cc-code/?comment=21582#post-id-21582There's also ctypes, which I've found useful in the past.Wed, 15 Jun 2011 21:51:31 -0500http://ask.sagemath.org/question/8165/call-cc-code/?comment=21582#post-id-21582