1

Trying to compile ocaml into javascript.

Some OCaml code I have put in https://gist.github.com/larsr/6b3cd6f62d54d56e3f9a uses the menhir parser, and the js_of_ocaml library together. I've installed them with opam.

The code comes from http://toss.sourceforge.net/ocaml.html. It is a lexer and a parser and a main program that calls them. The goal is to generate a javascript program from the ocaml code and run it from within a web page.

I am able to compile the first Main program using only menhir with make from the Makefile in the repo, which does

ocamlbuild -use-menhir -menhir "menhir --external-tokens Lexer" Main.native

and I can compile a program that only uses js_of_ocaml, with make Formula.js, which does

ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax \
      -syntax camlp4o -linkpkg -o Formula.byte Formula.ml
js_of_ocaml Formula.byte

My problem is that now I'm unable to get ocamlfind to build JsClient.js, with

make JsClient.js

so I can't produce javascript code for 'JsClient.ml'. The error I get is that the compiler can't find the module Js which is used by JsClient. The code seems to be in the opam library in my home-dir, but I can't get the right arguments to ocamlfind to use it.

How do I compile the JsClient.ml into JsClient.js?

4

1 回答 1

1

您用于编译JsClient.ml文件的规则不好。

JsClient.byte:
    ocamlbuild -use-menhir -menhir "menhir --external-tokens Lexer" 

如您所说,此文件使用模块Js,因此您需要使用与文件相同的方式进行编译Formula.ml

ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax \
      -syntax camlp4o -linkpkg -o JsClient.byte JsClient.ml
js_of_ocaml JSClient.byte
于 2015-09-24T12:58:29.940 回答