Ask Your Question

Call C/C++ Code

asked 2011-06-15 18:14:22 -0500

Jennifer Dylan gravatar image

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?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2011-06-15 22:53:06 -0500

Joaquim Puig gravatar image

You 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:

edit flag offensive delete link more

answered 2011-06-15 18:56:58 -0500

kcrisman gravatar image

updated 2011-06-15 18:57:19 -0500

Probably you will want to use Cython 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 for more tips.

edit flag offensive delete link more


There's also ctypes, which I've found useful in the past.

DSM gravatar imageDSM ( 2011-06-15 21:51:31 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-06-15 18:14:22 -0500

Seen: 855 times

Last updated: Jun 15 '11