HOWTO - Using LCC-Win32 to compile a external library to use with
        Maple^(R).

        Ricardo Y. Maeda - rymaeda@yahoo.com (10/09/2002)
        
        Explanations, corrections, questions e enlightenment are welcome!

        ...I apologize my Tarzan like english...

-----------------------------------------------------------------------------

Principle KISS (Keep it simple stupid):
I choice to decribe the process calling the compiler and linker at command
line level.

-----------------------------------------------------------------------------


With the C function give in Online Help for 'define_external' Maple function,
we create the file 'edrlib.c':


/*  Start **************** EDRLIB.C *************************************/
#include <windows.h>

int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
     return TRUE ;
}

_stdcall void mat_mult( double *A, double *B, double *C, int I, int J, int K )
{
     int i, j, k;
     double t;
     //MessageBox(NULL,"","",MB_OK);
     for( i = 0; i < I; ++i )
         for( k = 0; k < K; ++k ) {
             t = 0.0;
             for( j = 0; j < J; ++j )
             t += A[i*J+j] * B[j*K+k];
             C[i*K+k] = t;
         }
}
/*  End ****************** EDRLIB.C *************************************/



Note the '_stdcall' qualifier prepended the 'void mat_mult()' function.

We compile with the command:
lcc edrlib.c -O

The option '-O' set on the compiler optimizations.


We need to create one text file 'edrlib.def' to inform what functions
in 'edrlib.dll' will be exportable. 'edrlib.def' contents:

; Start ******************* EDRLIB.DEF ***********************************
EXPORTS
mat_mult
; End ********************* EDRLIB.DEF ***********************************


Now we can create 'edrlib.dll' with the command:
lcclnk -DLL -s edrlib.obj edrlib.def

The '-s' option suppress debuging info.


If nothing wrong have occurred, the file 'edrlib.dll' was created, to
use it is necessary place it in one of Windows path directories or at same
directory of Maple.

For testing purpose we can use the calling of 'mat_mult()' function give
as example in 'define_external' online Maple help, but note that some
changes have to be made in definitions of 'A', 'B' and 'C' matrices,
otherwise of 'C_order' we need to use 'Fortran_order':

mat_mult :=
> define_external('mat_mult',
> a::ARRAY(1..i,1..j,float[8]),
> b::ARRAY(1..j,1..k,float[8]),
> c::REF(ARRAY(1..i,1..k,float[8]),RETURN_ONLY),
> i::integer[4],
> j::integer[4],
> k::integer[4],
> LIB="EdrLib.dll"):
> A := Matrix(100,100,(i,j)->i/j,datatype=float[8],order=Fortran_order):
> B := Matrix(100,100,(i,j)->i*j,datatype=float[8],order=Fortran_order):
> C := Matrix(100,100,(i,j)->i*j,datatype=float[8],order=Fortran_order):
> C[4,5];C[5,4];C[100,100];

                                 20.


                                 20.


                                10000.

> mat_mult(A,B,C,100,100,100):
> C[4,5];C[5,4];C[100,100];

                               270680.


                         422937.500000000000


                               338350.

>


-----------------------------------------------------------------------------
