Re: Help with nlffi
brian <briand-/[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
I'm not sure what's going on but I'm 99% sure that your nlffi set-up
is correct.
So that would mean that something is wrong in the creation of the .so
file whic is in turn causing the the dynamic load to fail.
Look at the objdump utility. You should be able to use it to check
the contents of the .so file you created and make sure that bertrand
is in there. I _think_ it's objdump -t ?
Also try out ldd on the .so file and make sure that it is not
referencing an unresolved library, i.e. maybe your LDPATH is not set-
up correctly.
Also, try the following to create you shared library :
gcc -shared -Wall -pedantic -DPOLKA_NUM=3 polka.c -o polkagmp.so -lgmp
As I said, I'm pretty sure your nlffi set-up is correct. Something
is wrong with the dynamic library.
This format:
> structure LibH = struct
> local
> val lh = DynLinkage.open_lib
> { name = "./polkagmp.so", global = true, lazy = true }
> in
> fun libh s = let
> val sh = DynLinkage.lib_symbol (lh, s)
> in
> fn () => DynLinkage.addr sh
> end
> end
> end
Is what I always use. You might want to use the absolute pathname
for the library rather than the relative pathname.
Brian
On Apr 8, 2006, at 8:01 AM, Natalia Beatriz Bidart wrote:
> Hi all,
>
> brian wrote:
>> Natalia,
>> The
>>> error: syntax error: replacing ID with TYPE_NAME
>>> Likely cause: missing typedef declaration.
>> errors are due to the incomprehensible way that the standard C
>> libraries define macros and types and I think that the nlffi C
>> processor simply gets confused.
>> This a result of the goofy behavior and syntax of the C preprocessor.
>> The best strategy is to take your .h files and eliminate
>> absolutely _everything_ you possibly can leaving only those
>> routines, typedefs, etc... that you really_need.
>> Declarations with variable arguments will not work.
>> Things like stdio.h, stdlib.h, etc.. really need to be taken out.
>> My strategy is always to trim the .h file to the absolute minimum
>> as a starting point. Make that work and then begin to include more.
>> Also your FILES variable in the .make file should refer to the .h
>> file NOT the .c file.
>> e.g.
>> in bertrand.h:
>> extern void bertrand(void);
>> in polka.make change the FILES definition:
>> FILES=bertrand.h
>> I think those changes should make your example work.
>
> Thanks for your prompt response. I still don't understand few things:
>
> 1- I used a .c file following the "intr" example in which there is
> only a intr.c file defined, and with it the ML code is generated.
> And that intr.c file includes stdio.h inside... so how is this
> example working? where is the magic? (in this same example the
> intr.make file defines
> CPPO = -D__builtin_va_list=int)
>
> 2- I've followed your advice and I created a polka.h file with just
> the line:
>
> extern void bertrand(void);
>
> I left the polka.c file compiled in same directory as polka.cm,
> along with polka.o, polka.so and polkagmp.so as showing here:
>
> bn@DALI:~/tesis/nlffi-tests/polka$ ls -l
> total 32
> -rw-r--r-- 1 bn bn 164 2006-04-08 11:50 libh.sml
> -rw-r--r-- 1 bn bn 1689 2006-04-07 21:05 polka.c
> -rw-r--r-- 1 bn bn 92 2006-04-07 21:00 polka.cm
> -rwxr-xr-x 1 bn bn 1228 2006-04-08 00:47 polkagmp.so
> -rw-r--r-- 1 bn bn 28 2006-04-08 10:36 polka.h
> -rw-r--r-- 1 bn bn 253 2006-04-08 10:35 polka.make
> -rw-r--r-- 1 bn bn 2136 2006-04-08 00:47 polka.o
> -rwxr-xr-x 1 bn bn 3507 2006-04-08 00:47 polka.so
>
> When running 'sml -m polka.cm' I've got:
>
> bn@DALI:~/tesis/nlffi-tests/polka$ wsml -m polka.cm
> Standard ML of New Jersey v110.58 [built: Fri Mar 24 12:51:04 2006]
> [scanning polka.cm]
> [library $c/c.cm is stable]
> [attempting to load plugin $/make-tool.cm]
> [library $/make-tool.cm is stable]
> [library $smlnj/internal/cm-lib.cm is stable]
> [library $smlnj/internal/srcpath-lib.cm is stable]
> [library $SMLNJ-LIB/Util/smlnj-lib.cm is stable]
> [library $SMLNJ-BASIS/basis.cm is stable]
> $Execute: required privileges are:
> cm-init
> [library $smlnj/cm/cm.cm is stable]
> [library $smlnj/internal/cm-sig-lib.cm is stable]
> [library $/pgraph.cm is stable]
> [library $smlnj/internal/cm0.cm is stable]
> [library $smlnj/cm/tools.cm is stable]
> [plugin $/make-tool.cm loaded successfully]
> [make -f polka.make SMLNJ_BINDIR=/usr/local/sml/bin FFI/polka.cm]
> /usr/local/sml/bin/ml-nlffigen -DPOLKA_NUM=3 -include ../libh.sml -
> libhandle LibH.libh -dir FFI -cmfile polka.cm polka.h
> [scanning (polka.cm):FFI/polka.cm]
> [library $c/internals/c-int.cm is stable]
> [parsing (polka.cm):FFI/(polka.cm):f-bertrand.sml]
> [creating directory FFI/.cm/SKEL]
> [parsing (polka.cm):FFI/(polka.cm):callop-0.sml]
> [parsing (polka.cm):FFI/(polka.cm):fptr-rtti-0.sml]
> [parsing (polka.cm):FFI/(polka.cm):../libh.sml]
> [creating directory .cm/SKEL]
> [library $c/memory/memory.cm is stable]
> [compiling (polka.cm):FFI/(polka.cm):../libh.sml]
> [creating directory .cm/GUID]
> [creating directory .cm/x86-unix]
> [code: 384, env: 214 bytes]
> [compiling (polka.cm):FFI/(polka.cm):callop-0.sml]
> [creating directory FFI/.cm/x86-unix]
> [code: 284, env: 282 bytes]
> [compiling (polka.cm):FFI/(polka.cm):fptr-rtti-0.sml]
> [code: 528, env: 198 bytes]
> [compiling (polka.cm):FFI/(polka.cm):f-bertrand.sml]
> [code: 957, data: 37, env: 200 bytes]
> $Execute: required privileges are:
> c-int
> primitive
> FFI/polka.cm:10.30-11.14 Error: link-time exception in user program
> (polka.cm):FFI/(polka.cm):f-bertrand.sml
> DynLinkError
>
> /usr/local/bin/sml: Fatal error -- Uncaught exception Link with 0
> raised at ../cm/compile/link.sml:355.27-355.35
>
>
> I've tried two times, one with libh defined as:
>
> structure LibH = struct
> local
> val lh = DynLinkage.open_lib
> { name = "./polkagmp.so", global = true, lazy = true }
> in
> fun libh s = let
> val sh = DynLinkage.lib_symbol (lh, s)
> in
> fn () => DynLinkage.addr sh
> end
> end
> end
>
> and another without the explicit path to polkagmp.so:
>
> structure LibH = struct
> fun libh s = let
> val sh = DynLinkage.lib_symbol (DynLinkage.main_lib, s)
> in
> fn () => DynLinkage.addr sh
> end
> end
>
> Both tries threw same DynLinkError error. What's the compiler
> looking for that I'm not providing it?
> I'm attaching all source files in a tgz file just in case they're
> of any help.
>
> Thanks a lot, Natalia.
> <polka.tgz>
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642