Re: Help with nlffi
Natalia Beatriz Bidart <[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
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
(application/x-compressed-tar, 3.1 KB) - not displayed