Hi,
How do you link to external C libraries when calling camlp4? When calling ocamlc, we can use the -custom and -cclib flags in order to statically link a library. However, the camlp4 executable seems to ignore these flags when called. As an example, given the files:

-----------------

$ cat Makefile
all:
        gcc -c myadd.c
        ocamlc -c myadd.ml
        ocamlmktop -custom -cclib myadd.o -o mytop myadd.cmo
ocamlc -c -I +camlp4 -I +camlp4/Camlp4Parsers -pp camlp4of myquot.ml

clean:
        rm *.cmo
        rm *.cmi
        rm *.o

$ cat myadd.c
int add1(int x){
        return x+1;
}

$ cat myadd.ml
external add1 : int->int = "add1";;

$ cat myquot.ml
module CamlSyntax = Camlp4OCamlParser.Make(
    Camlp4OCamlRevisedParser.Make(Camlp4.PreCast.Syntax));;

open Camlp4.PreCast;;

let expr_of_string = CamlSyntax.Gram.parse_string CamlSyntax.expr_eoi;;
module MyGram = Camlp4.PreCast.MakeGram(Camlp4.PreCast.Lexer);;

let term = MyGram.Entry.mk "term";;
let term_eoi = MyGram.Entry.mk "term quotation";;


EXTEND MyGram
    GLOBAL: term term_eoi;
    term:
    [  "simple"
        [  `INT(i,_)  -> <:expr< $`int:Myadd.add1 i$ >> ]
    ];
    term_eoi:
    [[ t = term; `EOI -> t ]];
END;;

let expand_quot loc loc_opt s = MyGram.parse_string term_eoi loc s;;

Syntax.Quotation.add "abc" Camlp4.PreCast.Syntax.Quotation.DynAst.expr_tag
    expand_quot;;

$ cat test.ml
let x= <:abc< 4 >>;;

-----------------

If we call:

-----------------
$ ./mytop dynlink.cma camlp4of.cma myquot.cmo
        Objective Caml version 3.11.2

        Camlp4 Parsing version 3.11.2

# let x= <:abc< 4 >>;;
val x : int = 5
#
-----------------

everything works fine since mytop has been compiled with the correct C object file. However, if we try the following call:

-----------------
$ camlp4of myadd.cmo myquot.cmo test.ml
Camlp4: Uncaught exception: DynLoader.Error ("./myquot.cmo", "error while linking ./myquot.cmo.\nThe external function `add1' is not available")
-----------------

we have an error since the C object file has not been linked. How do we correctly preprocess the file test.ml?

Joe

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to