#17605: "How to call C code from Sage" thematic tutorial
-------------------------+-------------------------------------------------
       Reporter:         |        Owner:
  ncohen                 |       Status:  needs_review
           Type:         |    Milestone:  sage-6.5
  enhancement            |   Resolution:
       Priority:  major  |    Merged in:
      Component:         |    Reviewers:
  documentation          |  Work issues:
       Keywords:         |       Commit:
        Authors:         |  a84624002490417b18adb6534a1c73843822306e
  Nathann Cohen          |     Stopgaps:
Report Upstream:  N/A    |
         Branch:         |
  public/17605           |
   Dependencies:         |
-------------------------+-------------------------------------------------

Comment (by ncohen):

 Hello Volker,

 > You can link compiled C/C++ code with a stand-alone Cython project like
 in https://github.com/vbraun/lattice_phi4. Then just import as module in
 Sage.

 I tried it but I was not able to compile it. It seems that I am missing
 some headers.

 I kept on whipping my test files and go to something new, though: I was
 able to make it work provided that I copied libdoublevector.so to
 SAGE_ROOT/local/lib/.

 Now, I am trying to make it all run from my working directory but I meet
 the following problem:
 - When calling "%runfile double_vector_sage.pyx" there are two calls to
 GCC
 - The one which contains -ldoublevector is not the one that contains
 -L/home/ncohen/a

 As a result the second call always fails, because the library is not
 found.

 {{{
 sage: %runfile double_vector_sage.pyx
 Compiling ./double_vector_sage.pyx...
 ...
 RuntimeError: Error compiling ./double_vector_sage.pyx:
 running build
 running build_ext
 building '_home_ncohen_a_double_vector_sage_pyx_5' extension
 gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
  -I/home/ncohen/.Sage/local/include/csage
 -I/home/ncohen/.Sage/local/include
  -I/home/ncohen/.Sage/local/include/python2.7
  -I/home/ncohen/.Sage/local/lib/python/site-packages/numpy/core/include
  -I/home/ncohen/.Sage/src/sage/ext -I/home/ncohen/.Sage/src
  -I/home/ncohen/.Sage/src/sage/gsl -I.
 -I/home/ncohen/.Sage/local/include/python2.7
  -c _home_ncohen_a_double_vector_sage_pyx_5.c
  -o build/temp.linux-x86_64-2.7/_home_ncohen_a_double_vector_sage_pyx_5.o
  -w -O2 -L/home/ncohen/a/
 gcc -pthread -shared -L/home/ncohen/.Sage/local/lib build/temp.linux-
 x86_64-2.7/_home_ncohen_a_double_vector_sage_pyx_5.o
  -L/home/ncohen/.Sage/local/lib/ -L/home/ncohen/.Sage/local/lib
 -ldoublevector
  -lmpfr -lgmp -lgmpxx -lstdc++ -lpari -lm -lec -lgsl -lgslcblas -latlas
 -lntl
  -lcsage -lpython2.7 -o build/lib.linux-
 x86_64-2.7/_home_ncohen_a_double_vector_sage_pyx_5.so
  -L/home/ncohen/.Sage/local/lib
 }}}

 The header of my .pyx file is:
 {{{
 #clib doublevector
 #cargs -L/home/ncohen/a/
 }}}

 Thanks to you if you can give me some hint. In the meantime I'll be trying
 again to make it work.

 Nathann

--
Ticket URL: <http://trac.sagemath.org/ticket/17605#comment:9>
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.

Reply via email to