I'm new to OCaml, but its documentation makes me cry. I want to write a parser on ocaml and integrate it into c++ project.
I've made c++ - OCaml binding right like it is described here http://www.mega-nerd.com/erikd/Blog/CodeHacking/Ocaml/calling_ocaml.html
so I can get an executable that calling OCaml code with such commands:
- cat build.sh
- #/bin/bash
- mkdir -p build
- ocamlopt -c -o build/ocaml-called-from-c.cmx ocaml-called-from-c.ml
- ocamlopt -output-obj -o build/camlcode.o build/ocaml-called-from-c.cmx
- gcc -g -Wall -Wextra -c c-main-calls-ocaml.c -o build/c-main-calls-ocaml.o
- gcc build/camlcode.o build/c-main-calls-ocaml.o -lm -L ~/.opam/4.01.0/lib/ocaml -lasmrun -o c-main-calls-ocaml -ldl
But then I've add "open Genlex;;" to ocaml-called-from-c.ml and try to write simple parser for example, as it described here:
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Genlex.html
As it saying: "One should notice that the use of the parser keyword and associated notation for streams are only available through camlp4 extensions. This means that one has to preprocess its sources e. g. by using the "-pp" command-line switch of the compilers."
but
ocamlopt -pp camlp4 -o build/ocaml-called-from-c.cmx -c ocaml-called-from-c.ml
gets
Parse error: entry [implem] is empty Error while running external preprocessor Command line: camlp4 'ocaml-called-from-c.ml' > /tmp/ocamlpp162c63
without -pp it falling on:
parser | [< n1 = parse_atom; n2 = parse_remainder n1 >] -> n2
with
File "ocaml-called-from-c.ml", line 99, characters 13-14: Error: Syntax error
-pp camlp4oby-syntax camlp4o. AFAIR pp is used to specify syntax extension for camlp4. Also it will be great if you will use ocamlfind to invoke OCaml. And if you will paste link on github it will be easy for us to stufy your problem. - Kakadu