Re: Help with nlffi
Natalia Beatriz Bidart <[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
brian wrote:
> I've been doing a lot of work with nlffi.
>
> Just let me know if you need any help.
Actually yes :-$. I'm really stuck with some errors thrown by ML
compiler when experimenting with a certain polyhedral library: polka (my
final goal is to be able to interface this library to provide a ML
program that does things with polyhedra).
My situation:
I have a C file (polka.c, attached to this email) that uses the polka
library.
So this C file compiles just fine when doing the following (note that I
have to link against libpolkag and libgmp):
bn@DALI:~/tesis/nlffi-tests/polka$ gcc -Wall -pedantic -DPOLKA_NUM=3 -c
-o polka.o polka.c
bn@DALI:~/tesis/nlffi-tests/polka$ gcc -Wall -pedantic -o polka polka.o
-lpolkag -lgmp
Before running ml-nlffigen, I run:
bn@DALI:~/tesis/nlffi-tests/polka$ gcc -Wall -pedantic -DPOLKA_NUM=3 -c
-o polka.o polka.c
bn@DALI:~/tesis/nlffi-tests/polka$ ld -shared -o polka.so polka.o
bn@DALI:~/tesis/nlffi-tests/polka$ ld -shared -o polkagmp.so polka.so
/usr/lib/libgmp.so
Which produces a polkagmp.so library that I later use in libh.sml file.
I've coded the following files in order to use nlffi:
(*********************************************************)
(* polka.cm file *)
library
library(FFI/polka.cm)
is
$/basis.cm
$c/c.cm
FFI/polka.cm : make (-f polka.make)
(*********************************************************)
(*********************************************************)
(* libh.sml file *)
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
(*********************************************************)
(*********************************************************)
(* polka.make file *)
FILES = polka.c
H = LibH.libh
D = FFI
HF = ../libh.sml
CF = polka.cm
#CPPO = -D__builtin_va_list=int -DPOLKA_NUM=3
CPPO = -DPOLKA_NUM=3
$(D)/$(CF): $(FILES)
$(SMLNJ_BINDIR)/ml-nlffigen $(CPPO) -include $(HF) -libhandle
$(H) -dir $(D) -cmfile $(CF) $^
(*********************************************************)
When I run 'sml -m polka.cm' I get the following:
bn@DALI:~/tesis/nlffi-tests/polka$ sml -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.c
"/usr/lib/gcc/i486-linux-gnu/3.4.5/include/stdarg.h":43.70-87: error:
syntax error: replacing ID with TYPE_NAME
Likely cause: missing typedef declaration.
"/usr/local/include/polka/pkint.h":187.50-56: error: syntax error:
replacing ID with TYPE_NAME
Likely cause: missing typedef declaration.
(... and a lot more like the last error)
So I took a look into /usr/lib/gcc/i486-linux-gnu/3.4.5/include/stdarg.h
file and I found that line 43 has the following definition:
typedef __builtin_va_list __gnuc_va_list;
which sadly said nothing to me :-(, but then I realized that I've
commented out the (absolutely black magic) definition of
-D__builtin_va_list=int in 'polka.make'. So I uncommented it, and tried
again: the stdarg error wasn't there anymore, but all the polka errors
remained still.
Line 187 of /usr/local/include/polka/pkint.h shows this:
static inline void pkint_print(pkint_t a)
Can you give me a hand with this? I really need to use that library
along with gmp library.
> Probably best to post to the list to help out everyone else too.
I absolutely agree on this. Post to list done.
Bests regards, Natalia.
polka.c
(text/x-csrc, 1.6 KB)
#include <polka/polka.h>
#include <polka/pkint.h>
#include <polka/vector.h>
#include <polka/bit.h>
#include <polka/satmat.h>
#include <polka/matrix.h>
#include <polka/poly.h>
#include <stdlib.h>
#include <stdio.h>
void bertrand(void) {
int nbdims;
int dimx;
int dimy;
poly_t* po;
poly_t* pu;
equation_t eqns[2];
polka_initialize(false,10,5000);
nbdims = 2;
dimx = 0; dimy = 1;
/* Universe polyhedron with variables x and y */
pu = poly_universe(nbdims);
poly_print(pu);
/* Equation x := 2 */
eqns[0].var = dimx;
eqns[0].expr = vector_alloc(polka_dec+nbdims);
pkint_set_ui(eqns[0].expr[0],1);
pkint_set_ui(eqns[0].expr[polka_cst],2);
/* Equation y := 2 */
eqns[1].var = dimy;
eqns[1].expr = vector_alloc(polka_dec+nbdims);
pkint_set_ui(eqns[1].expr[0],1);
pkint_set_ui(eqns[1].expr[polka_cst],2);
/* Perform the assignements */
po = poly_assign_variables(pu,eqns,2);
poly_print(po);
poly_free(po);
vector_free(eqns[0].expr,polka_dec+nbdims);
vector_free(eqns[1].expr,polka_dec+nbdims);
/* Equation x := 2/3 */
eqns[0].var = dimx;
eqns[0].expr = vector_alloc(polka_dec+nbdims);
pkint_set_ui(eqns[0].expr[0],3);
pkint_set_ui(eqns[0].expr[polka_cst],2);
/* Equation y := 4/5+x */
eqns[1].var = dimy;
eqns[1].expr = vector_alloc(polka_dec+nbdims);
pkint_set_ui(eqns[1].expr[0],5);
pkint_set_ui(eqns[1].expr[polka_cst],4);
pkint_set_ui(eqns[1].expr[polka_dec+dimx],5);
/* Perform the assignements */
po = poly_assign_variables(pu,eqns,2);
poly_print(po);
poly_free(po);
poly_free(pu);
vector_free(eqns[0].expr,polka_dec+nbdims);
vector_free(eqns[1].expr,polka_dec+nbdims);
polka_finalize();
}