简体   繁体   中英

Compiling ocaml can't find module in opam library, Js.ml in js_from_ocaml

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 ?

The rule that you use to compile the JsClient.ml file is not good.

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

As you said, this file use the module Js so you need to compile with the same way than the file 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM