#17605: "How to call C code from Sage" thematic tutorial
-------------------------+-------------------------------------------------
Reporter: | Owner:
ncohen | Status: needs_work
Type: | Milestone: sage-6.5
enhancement | Resolution:
Priority: major | Merged in:
Component: | Reviewers: Karl-Dieter Crisman
documentation | Work issues:
Keywords: | Commit:
Authors: | 96177d8ed62e5c88325c95f168406b27249b2ea1
Nathann Cohen | Stopgaps:
Report Upstream: N/A |
Branch: |
public/17605 |
Dependencies: |
-------------------------+-------------------------------------------------
Changes (by kcrisman):
* status: needs_review => needs_work
* reviewer: => Karl-Dieter Crisman
Comment:
Issues I found.
* My compiler gives this.
{{{
$ gcc hello.c -o hello; ./hello
hello.c: In function ‘main’:
hello.c:7: warning: return type of ‘main’ is not ‘int’
Hello World
}}}
* Inconsistent names here:
{{{
+ def my_interface_function():
+ hello_world() # This is the C function from hello.c
...
+ sage: my_bridge_function()
+ Hello World
}}}
* Compiler error:
{{{
sage: %runfile hello_sage.pyx
Compiling ./hello_sage.pyx...
Error compiling cython file:
Error converting ./hello_sage.pyx to C:
Error compiling Cython file:
------------------------------------------------------------
...
include "interrupt.pxi" # ctrl-c interrupt block support
include "stdsage.pxi" # ctrl-c interrupt block support
include "cdefs.pxi"
cdef extern from "hello.c":
void hello_world()
^
------------------------------------------------------------
_Users_..._hello_sage_pyx_0.pyx:7:0: Expected an increase in indentation
level
}}}
* Even after fixing this:
{{{
sage: %runfile hello_sage.pyx
Compiling ./hello_sage.pyx...
Error compiling cython file:
Error compiling ./hello_sage.pyx:
running build
...
_Users_..._hello_sage_pyx_0.c:349:19: fatal error: hello.c: No such file
or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
}}}
Maybe my file needs to be in my `PATH`? But that didn't seem to help.
* And since presumably I needed to compile `double_vector.c` first, I
tried that, but...
{{{
$ gcc double_vector.c -o double_vector
double_vector.c: In function ‘sum_of_two_vectors’:
double_vector.c:4: warning: incompatible implicit declaration of built-in
function ‘malloc’
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
}}}
SO tells me there are two errors - need to include stdio.h and then
compile with `-c` or provide a main function. Still get the weird error
about it not existing when I try to `%runfile`, though.
* Similar problems with the final library example.
--
Ticket URL: <http://trac.sagemath.org/ticket/17605#comment:27>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.