Making and using a DLL consists of three major steps
Let us consider a simple C program
vecsum.c
which sums up a vector:
#include "dll.h" EXTERN int EXPORT sum (double *x, double *n, double *s) { long i, nn = (long) *n; *s=0.0; for (i=0; i<nn; i++) *s = *s + *(x+i); return (0); }
Note that the include file dll.h
defines the
symbols EXTERN
and EXPORT
in a proper way for the
below mentioned compiler.
The function SUN Solaris/GNU C++ can be compiled to a shared
library for instance with the GNU C-Compiler
gcc -G -o vecsum.so vecsum.c
from the Unix shell prompt.
To use the DLL in XploRe requires the following simple steps.
x
and initialize the result s
x=1:10 s=0
h=
dlopen
("vecsum.so")
Note that XploRe needs to be able to find this library. From
XploRe you can set the path for DLLs by
setenv
("xpl4dll","/your_absolute_path_to_the_dll")
Alternatively you can give the absolute path within the
dlopen
command.
sum
from the DLL for x
dlcall
("sum",x, rows(x),s)
As a result you should find s
having the value 55 which
is the sum for the numbers 1 to 10.