Ask Your Question

linking libraries in cython

asked 2010-09-07 19:22:49 +0200

maldun gravatar image


I have the following problem: I want to link an extern library like for example -lm to cython.

If I now write for example the following problem:

#clib: m

cdef extern from "math.h":
    double sin(double)

def f(x):
    return sin(x)

I get the following errors:

Traceback (most recent call last):
`File "<stdin>", line 1, in <module>
 File "", line 10, in <module>
 exec compile(u'_support_.cython_import_all("/home/maldun/.sage/sage_notebook.sagenb        /home/admin/0/code/sage14.spyx", globals())
 File "", line 1, in <module>

 File "/home/maldun/sage/sage-4.5.2/local/lib/python2.6/site-packages/sagenb-0.8.2-py2.6.egg  /sagenb/misc/", line 519, in cython_import_all
 File "/home/maldun/sage/sage-4.5.2/local/lib/python2.6/site-packages/sagenb-0.8.2-py2.6.egg/sagenb/misc/", line 496, in cython_import
 File "/home/maldun/sage/sage-4.5.2/local/lib/python2.6/site-packages/sage/misc/", line 409, in cython
 raise RuntimeError, "Error compiling %s:\n%s\n%s"%(filename, log, err)
 RuntimeError: Error compiling /home/maldun/.sage/sage_notebook.sagenb/home/admin/0/code/sage14.spyx:
 running build
 running build_ext
 building '_home_maldun__sage_sage_notebook_sagenb_home_admin_0_code_sage14_spyx_0' extension
 creating build
 creating build/temp.linux-x86_64-2.6
 gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/home   /maldun/sage/sage-4.5.2/local/include/csage/ -I/home/maldun/sage/sage-4.5.2/local/include/ -I/home/maldun/sage/sage-4.5.2/local/include/python2.6/ -I/home/maldun/sage/sage-4.5.2/local/lib/python2.6/site-packages/numpy/core/include -I/home/maldun/sage/sage-4.5.2/devel/sage/sage/ext/ -I/home/maldun/sage/sage-4.5.2/devel/sage/ -I/home/maldun/sage/sage-4.5.2/devel/sage/sage/gsl/ -I/home/maldun/.sage/sage_notebook.sagenb/home/admin/0/code -I/home/maldun/sage/sage-4.5.2/local/include/python2.6 -c _home_maldun__sage_sage_notebook_sagenb_home_admin_0_code_sage14_spyx_0.c -o build/temp.linux-x86_64-2.6/_home_maldun__sage_sage_notebook_sagenb_home_admin_0_code_sage14_spyx_0.o -w -O2
 creating build/lib.linux-x86_64-2.6
 gcc -pthread -shared build/temp.linux-x86_64-2.6/_home_maldun__sage_sage_notebook_sagenb_home_admin_0_code_sage14_spyx_0.o -L/home/maldun/sage/sage-4.5.2/local//lib/ -L/home/maldun/sage/sage-4.5.2/local/lib -l: -lm -lmpfr -lgmp -lgmpxx -lstdc++ -lpari -lm -lcurvesntl -lg0nntl -ljcntl -lrankntl -lgsl -lgslcblas -latlas -lntl -lcsage -lpython2.6 -o build/lib.linux-x86_64-2.6/ -L/home/maldun/sage/sage-4.5.2/local//lib

/usr/bin/ld: cannot find -l:
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1`

So now my questions: Why does this fail? Am I able to link labraries anyhow? Can I link external libraries into sage that are installed on my system but not in sage like fftw? Or have I to install them somehow into sage before using it?

Thanx in Advance! Maldun

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2010-09-07 19:48:12 +0200

Mike Hansen gravatar image

You just need to have

#clib m

instead of

#clib: m

Then, everything should work.

edit flag offensive delete link more



Thanx that worked! Is then the last code line in this tutorial ( ) false, outdated or does sage handle this different?

maldun gravatar imagemaldun ( 2010-09-08 05:53:39 +0200 )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

1 follower


Asked: 2010-09-07 19:22:49 +0200

Seen: 1,271 times

Last updated: Sep 07 '10