ocaml - 如何编译使用 JsooTop 模块的文件?
问题描述
我在一个名为的文件中有这个main.ml
:
let () = JsooTop.initialize ()
我尝试使用以下方法编译文件:
ocamlfind ocamlc -package js_of_ocaml -linkpkg -o main.byte main.ml
但是出现了这个错误:
File "main.ml", line 1, characters 9-27:
Error: Unbound module JsooTop
我的机器上似乎JsooTop
不存在,所以我运行opam install js_of_ocaml-toplevel
,并尝试使用以下命令再次编译文件:
ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml-toplevel -linkpkg -o main.byte main.ml
js_of_ocaml main.byte
但我收到警告:
来自的警告ocamlfind
:
findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /usr/lib/ocaml, /usr/lib/ocaml/compiler-libs
js_of_ocaml
来自可执行文件的警告:
There are some missing primitives
Dummy implementations (raising 'Failure' exception) will be used if they are not available at runtime.
You can prevent the generation of dummy implementations with the commandline option '--disable genprim'
Missing primitives provided by +dynlink.js:
caml_add_debug_info
caml_dynlink_add_primitive
caml_dynlink_get_current_libs
caml_dynlink_lookup_symbol
caml_dynlink_open_lib
caml_remove_debug_info
Missing primitives provided by +toplevel.js:
caml_get_current_environment
caml_get_section_table
caml_invoke_traced_function
caml_realloc_global
caml_reify_bytecode
caml_static_alloc
caml_static_free
caml_static_release_bytecode
caml_terminfo_setup
我的问题是:编译使用该JsooTop
模块的文件的正确方法是什么?
解决方案
首先,确保存在所需的 OPAM 包:
opam install js_of_ocaml js_of_ocaml-toplevel
要构建使用该JsooTop
模块的程序,请按以下方式编译文件:
ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml-toplevel -linkpkg -o main.byte main.ml
js_of_ocaml --toplevel --dynlink +dynlink.js +toplevel.js main.byte
注意包含--toplevel
、--dynlink
、+dynlink.js
和+toplevel.js
。上面的命令将生成一个名为main.js
.
推荐阅读
- django - 如何在 django rest 框架中使用 hyperlinkedModelSerializer
- c# - 检查是否接地而不使用 oncollision 进入/退出?
- npm - 无法通过 UI 将 npm 工件上传到 Sonatype Nexus
- sql - Postgres:如何检查时间桶中的多个值的记录
- sql - 过滤不包含数字的记录
- flutter - Flutter 小部件测试找不到 InputDecoration.errorText
- python - Pandas/Numpy 如何生成滚动计数列?
- bash - 使用 Bash 搜索 csv 文件中的列,在 txt 文件中找到它,然后如果找到,将第 1 列和第 2 列从第一个 csv 输出到第二个 csv
- c# - 如何从 EF Core 中的存储过程中获取对象列表?
- snakemake - Snakemake 在执行期间退出规则