1
votes

I'm exploring NLFFI (No Longer Foreign Function Interface), its implementation in SML/NJ. The "math" example works, but "pdb" gives an error:

FFI/pdb.cm:53.5-53.21 Error: link-time exception in user program (pdb.cm):FFI/(pdb.cm):../pdbhandle.sml
DynLinkErrornlffi/lib/memory/linkage-dlopen.sml:67.26-67.40

/usr/lib/smlnj/bin/sml: Fatal error -- Uncaught exception Link with 0 raised at ../cm/compile/link.sml:357.28-357.35

My shared library gives the same error. I think that the error is in "pdbhandle.sml" where dynamic linking goes, because "math" links the SML/NJ runtime library DynLinkage.main_lib and "pdb" links its own library. I tried to load the library manually:

sml -m "\$c/internals/c-int.cm"

and

DynLinkage.open_lib { name = "./pdb.so", global = true, lazy = true };

I get

uncaught exception DynLinkError raised at: nlffi/lib/memory/linkage-dlopen.sml:67.26-67.40

DynLinkage.open_lib { name = "/usr/lib/libgmp.so.10.2.0", global =
true, lazy = true };

gives the same error.

$ ls -l /usr/lib/libgmp.so.10.2.0

-rwxr-xr-x 1 root root 488208 бер 26 01:03 /usr/lib/libgmp.so.10.2.0

I see that DynLinkError has an argument, but SML/NJ does not show it. (BTW, is it a normal behavior?) I'm stuck here because I don't know what the error message is.

1

1 Answers

1
votes

It turned out that I was linking a library for the x86_64 architecture, but SML/NJ is x86-program. (I'm using ArchLinux x86_64 Multilib.)

DynLinkage.open_lib { name = "/usr/lib32/libgmp.so.10.2.0"
    , global = true, lazy = true };

works.

I print an argument of an exception by an ugly expression

(DynLinkage.open_lib { name = lib_file_name, global = true, lazy = true }
    ; raise Div)
    handle DynLinkage.DynLinkError x => x;