如何在js_of_ocaml中使用模块? [英] How to use modules with js_of_ocaml?

查看:78
本文介绍了如何在js_of_ocaml中使用模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用OCaml编写并使用js_of_ocaml编译为javascript的网站项目.只要使用命令ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o -linkpkg -o file.byte file.ml只有一个源文件,它就可以很好地工作,但是我想在我的项目中包括几个模块.我该怎么办?

I am currently working on a website project written in OCaml and compiled to javascript using js_of_ocaml. It works pretty well as long as I have only one source file using the command ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o -linkpkg -o file.byte file.ml but I would like to include several modules in my project. How can I do that ?

其他模块实际上是ocamllex和menhir编写的词法分析器和解析器.我已经阅读了教程有关如何将ocamllex和menhir与js_of_ocaml一起使用的方法,但是它在哪里做出了错误的假设js_of_ocaml已安装(我在opam中安装了它),它使用ocamlbuild,并且我想知道如何手工操作而不使用诸如ocamlbuild之类的自动化工具.

The other modules are actually a lexer and a parser poduced by ocamllex and menhir. I have read a tutorial on how to use ocamllex and menhir with js_of_ocaml but it makes wrong assumptions on where js_of_ocaml is installed (I installed it with opam) and it uses ocamlbuild and I want to know how to do it by hand without using an automated tool such as ocamlbuild.

推荐答案

我通过尝试理解官方示例的makefile找到了解决方案.

I found the solution by trying to understand the makefiles for the official examples.

这是我的Makefile:

Here is my Makefile :

OBJS=file1.cmo file2.cmo file3.cmo
NAME=projectname
OCAMLC=ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o

$(NAME).byte: $(OBJS)
        $(OCAMLC) -linkpkg -o $@ $(OBJS)

$(NAME).js: $(NAME).byte
        js_of_ocaml $<

%.cmo: %.ml
        $(OCAMLC) -c $<
...

这篇关于如何在js_of_ocaml中使用模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆