Hi,
I have developed a function in C using a library called flint (http://
www.flintlib.org/ I am actually using the unreleased flint2), and am
in the process of trying to wrap it using cython. I keep on running
into a particular error when I try to use some functions.
First here is the code in a file sineDemo.pxd (the name is because I
built it up from some example code that used math.h):
cdef extern from "stdlib.h":
ctypedef unsigned long size_t
void free(void *ptr)
void *malloc(size_t size)
void *realloc(void *ptr, size_t size)
cdef extern from "math.h":
double sin(double)
cdef extern from "../../flint2/fmpz.h":
ctypedef struct fmpz_t:
pass
void fmpz_init(fmpz_t f)
void fmpz_clear(fmpz_t f)
void fmpz_print(fmpz_t x)
void fmpz_neg(fmpz_t, fmpz_t)
#void fmpz_set_si(fmpz_t f, long val)
#char * fmpz_get_str(char * str, int b, fmpz_t f)
And here is the file sineDemo.pyx:
cimport sineDemo
def evalWithSine(array):
vect = []
for i in array:
vect.append(sineDemo.sin(<double>i))
return vect
def twoSine(x):
return sineDemo.sin(<double>x)
def call_fmpz_t():
cdef sineDemo.fmpz_t number
def set_fmpz_t():
cdef sineDemo.fmpz_t number
sineDemo.fmpz_init(number)
sineDemo.fmpz_clear(number)
sineDemo.fmpz_print(number)
sineDemo.fmpz_neg(number, number)
#cdef long num2 = <long>num
#sineDemo.fmpz_set_si(number, num2)
#cdef char * word
#word = sineDemo.fmpz_get_str(word, <int>10, number)
As you can hopefully see I have tried to import functions from a
header file fmpz.h. The function fmpz_init, fmpz_clear, fmpz_print all
work fine (and are inline c functions if that makes any difference),
so far as I can tell.
Trying to use fmpz_neg or fmpz_set_si or fmpz_get_str produces the
following king of error when I try and import sineDemo in python:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: ./sineDemo.so: undefined symbol: fmpz_neg
Also here is what gets printed out when I run the setup script:
running build_ext
cythoning sineDemo.pyx to sineDemo.c
building 'sineDemo' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -
Wstrict-prototypes -I/home/danielwoodhouse/flint2 -fPIC -I/usr/include/
python2.6 -c sineDemo.c -o build/temp.linux-x86_64-2.6/sineDemo.o
In file included from ../../flint2/fmpz.h:31,
from sineDemo.c:158:
../../flint2/nmod_vec.h: In function ‘_nmod_vec_copy’:
../../flint2/nmod_vec.h:160: warning: implicit declaration of function
‘mpn_copyi’
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -L/home/wbhart/
lib/:-L/home/danielwoodhouse/flint2/:-L/usr/local/lib/ -I/home/
danielwoodhouse/flint2 build/temp.linux-x86_64-2.6/sineDemo.o -lmpir -
o sineDemo.so
I don't think the warning about mpn_copyi has anything to do with the
error.
If anyone can tell me what I am doing wrong or give any helpful
suggestions, that would be fantastic. Please do ask further questions.
-Daniel
What is causeint