Python'dan callable olmak için bir c kodu sarmaya çalışıyorum.Hata Yükleme Modülü ./exp.so Tanımsız Sembol
kodu:
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "math.h"
int givernd(int krp1,int krp2)
{
int trye;
int inp1=krp1;
int inp2=krp2;
time_t broke;
if(inp1 > inp2)
{ printf("error");
exit(0);
}
if((inp1)=(inp2-1))
{ printf("error");
exit(0);
}
srand(time(&broke));
trye=rand()%krp2;
if(trye<krp1)
{
return(trye+krp1+1);
}
if(trye==krp1)
{
return(trye+1);
}
return(trye);
}
.ı dosyası:
/* now1.i */
%module now1
%{
/* Put header files here or function declarations like below */
extern int givernd(int krp1,int krp2);
%}
extern int givernd(int krp1,int krp2);
deneme 1:
$ swig -python now1.i
$ gcc -c -fPIC now1_wrap.c -I/usr/include/python2.7
$ gcc -shared -fpic now1_wrap.o -o now1_wrap.so -lc
$ python
Python 2.7.3 (default, Jun 22 2015, 19:43:34)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import now1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initnow1)
deneme 2:
$ swig -python now1.i
$ gcc -fpic -I/usr/include/python2.7 -c now1_wrap.c
$ gcc -shared now1_wrap.o -o now1.so
$ python
Python 2.7.3 (default, Jun 22 2015, 19:43:34)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import now1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: ./now1.so: undefined symbol: givernd
>>>
Neyi yanlış yapıyorum?
Başlangıç noktası yinelenen ana olacak bir test işlevi eklemem gerekip gerekmediğini merak ediyorum, ancak el kitabı gerekmediğini söylüyor.
thanks.the öğretici oldukça zayıftı ve ben aptalca sayesinde either.again çok "-o" eklemek vermedi. – blute