First time here? Check out the FAQ!

Ask Your Question
3

Call C/C++ Code

asked 13 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
4

answered 13 years ago

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:

http://www.sagemath.org/doc/numerical_sage/ctypes.html

Preview: (hide)
link
3

answered 13 years ago

kcrisman gravatar image

updated 13 years ago

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.

Preview: (hide)
link

Comments

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

DSM gravatar imageDSM ( 13 years ago )

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 13 years ago

Seen: 1,506 times

Last updated: Jun 16 '11