how to access to a compiled function in a C interface
Collette Yann
ycollette at free.fr
Thu Aug 14 15:04:56 CEST 2008
Hello,
I would like to access to a compiled function from a C interface.
Here is the intersting part of the optim documentation:
C=['#include <math.h>'
'double sq(double x)'
'{ return x*x;}'
'void rosenc(int *ind, int *n, double *x, double *f, double *g, '
' int *ti, float *tr, double *td)'
'{'
' double p;'
' int i;'
' p=td[0];'
' if (*ind==2||*ind==4) {'
' *f=1.0;'
' for (i=1;i<*n;i++)'
' *f+=p*sq(x[i]-sq(x[i-1]))+sq(1.0-x[i]);'
' }'
' if (*ind==3||*ind==4) {'
' g[0]=-4.0*p*(x[1]-sq(x[0]))*x[0];'
' for (i=1;i<*n-1;i++)'
'
g[i]=2.0*p*(x[i]-sq(x[i-1]))-4.0*p*(x[i+1]-sq(x[i]))*x[i]-2.0*(1.0-x[i]);'
' g[*n-1]=2.0*p*(x[*n-1]-sq(x[*n-2]))-2.0*(1.0-x[*n-1]);'
' }'
'}'];
mputl(C,TMPDIR+'/rosenc.c')
// compile the C code
l=ilib_for_link('rosenc','rosenc.o',[],'c',TMPDIR+'/Makefile');
// incremental linking
link(l,'rosenc','c');
Once this function is compiled and linked, the 'rosenc' doesn't appears
as a variable. I am only able to use this function via a call to fort.
Where is this function in scilab ?
How to I get a pointer to this function in a C interface ?
YC
More information about the dev
mailing list