[clean-list] htoclean sorrows

Marco Kesseler m.kesseler at aia-itp.com
Thu May 11 12:22:45 MEST 2006


Hi,

for what it is worth, I can only provide the following information about 
linking to a dll from Clean (my knowledge is limited):

http://www.xs4all.nl/~keslr/functional/clean/howto/cleandll.html

With respect to the symbols. Clean uses the "stdcall" calling convention, 
which is actually the standard for the Win32 API. More info on this can be 
found, e.g. in:

http://wyw.dcweb.cn/stdcall.htm

regards,
Marco


----- Original Message ----- 
From: "Matthew Bromberg" <mattcbro at earthlink.net>
To: <clean-list at science.ru.nl>
Sent: Thursday, May 11, 2006 6:33 AM
Subject: [clean-list] htoclean sorrows


>I am attempting to link to the acml BLAS .dll in a simple test of the clean 
>FFI.  I have a windows XP 64 amd x2
> machine.
>
> Unfortunately after several days of playing around with it, including 
> downloading an
> updated linker, I could not get it to work either using Microsofts VC 2003 
> or VC 6.0 toolset.
> I'm afraid I will have to switch to Haskell for now since it is critical 
> that I am able to link to external dynamic libraries.
>
>
> The description of how to do this is contained in this one paragraph in 
> the documentation
>
> "The Clean linker for Windows and MacOS does not support importing symbols 
> from DLLs/shared libraries using object files (import libraries), because 
> some relocations are not implemented. Instead symbols from a DLL/shared 
> library are imported using an ascii file that lists the symbols that are 
> exported by a DLL/shared library. The first line of such a file contains 
> the name of the DLL/shared library (with .dll extension on windows, 
> usually no full pathname), the next lines contain the names of the 
> exported symbols (only functions), each symbol on one line, spaces and 
> comments are not permitted. Examples can be found in the 'Clean System 
> Files' folder of the StdEnv.'
>
> Some things that are missing from this description are the fact that the 
> symbol format has an @number syntax appended to each symbol that is not 
> explained, and the menu path to the IDE  menus that permit the import of 
> the symbol file and the import of the DLL are tricky to find and frankly I 
> can't be sure I got it correct. Also there is no description of how to add 
> the object file.
>
> Here is my import file acml_library:
> libacml_dll.dll
> daxpy at 6
>
>
> I have no idea really what the @6 means.  I guessed it means push 6 32 bit 
> words on to the argument stack, but I can't be sure.  Is this supposed to 
> be a .def format?  Here is my C code, cmatrix.c
>
> #include "acml.h"
> #include "Clean.h"
> #include "cmatrix.h"
>
> /* real multiply and accumulate using a stride of 1
> * y = y + alpha * x
> * the array length is returned */
> int rmac(double alpha, CleanRealArray x,  CleanRealArray y )
> {
> int nlen ;
> nlen = CleanRealArraySize(y);
>
> daxpy(nlen, alpha, x, 1, y, 1) ;
> return(nlen) ;
> }
>
>
> /*
> int main()
> {
> double xa[5] = {0.0 , 0.0, 1.0, 2.0, 3.0} ;
> double ya[5] = {0.0, 0.0, 3.0, 2.0, 1.0} ;
> int k, j, *iptr ;
> double *x, *y ;
>
> x = &(xa[2]) ;
> y = &(ya[2]) ;
> iptr = (unsigned int *) &(x[0]) ;
> iptr[-2] = 3 ;
> iptr = (unsigned int *) &(y[0]) ;
> iptr[-2] = 3 ;
> k = rmac(2.0, x, y) ;
> printf("length = %d\n", k) ;
> for (j = 0 ; j < 3 ; j++) {
>    printf("y[%d] = %g ", j, y[j]) ;
> }
> printf("\n") ;
> return(k) ;
> }
> */
>
> This code links and works correctly if I uncomment main() and link to the 
> acml lib via C.  htoclean and the compiler also run without complaint. 
> Here is my matrix.icl file:
>
> module matrix
> import StdEnv
> import StdList
> import StdArray
> import cmatrix
>
>
>
>
> x :: {#Real}
> x = {0.5, -0.5, 1.0, -1.0}
>
>
> // unboxed array IO, uniqueness
>
> y :: *{#Real}
> y = {1.0, 2.0, 3.0, 4.0}
> // q = {z+ 2.0 * w \\ z <-: y & w <-: x}
>
>
> // Start = q
>
>
>
> nlen :: *Int
> nlen = 0
>
>
> Start :: (*{#Real}, Int)
> Start
> #! nlen = rmac  2.0 x  y
> = (y, nlen)
>
>
> Now everything compiles and links correctly but fails on execution with 
> the cryptic words
> from the operating system that matrix.exe is not a valid Win32 
> application.  It then exits with the words
> access denied in the Dos window.  It does this with both the old linker 
> and the new linker.
>
>
> _______________________________________________
> clean-list mailing list
> clean-list at science.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/clean-list
> 



More information about the clean-list mailing list