制作兼容的ocaml,camlp4,ppx,node,js_of_ocaml,ocamlbuild

时间:2016-05-16 14:16:25

标签: ocaml opam camlp4 js-of-ocaml ppx

安装npmnode后,使用js_of_ocaml编译OCaml文件会出错,因此我做了opam switch reinstall system

:testweb $ opam switch reinstall system
Your system compiler has been changed. Do you want to upgrade your OPAM installation ? [Y/n] y

=-=- Upgrading system -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=   
[WARNING] base-ocamlbuild.base is not available because it requires OCaml >= 3.10 & < 4.03. Skipping.
[WARNING] camlp4.4.02+system is not available because your system doesn't comply with preinstalled &
      ocaml-version >= "4.02" & ocaml-version < "4.03". Skipping.
[WARNING] ppx_tools.4.02.3 is not available because your system doesn't comply with ocaml-version >=
      "4.02.0" & ocaml-version < "4.03.0". Skipping.
The following dependencies couldn't be met:
  - deriving -> camlp4
Your request can't be satisfied:
  - camlp4 is not available because your system doesn't comply with ocaml-version >= "4.04".

No solution found, exiting
The former package state can be restored with opam switch import "/Users/softtimur/.opam/backup/state-20160418124642.export" --switch system

然后,我意识到ocamlfind不再起作用了:

:testweb $ ocamlfind ocamlc -package js_of_ocaml.ppx -linkpkg cubes.ml -o T
-bash: /Users/softtimur/.opam/system/bin/ocamlfind: No such file or directory

PS:node --version给出v6.1.0; npm --version给出3.8.6; ocaml -version给出The OCaml toplevel, version 4.03.0js_of_ocaml --version2.7,但在opam swtich reinstall system之后,它会-bash: /Users/softtimur/.opam/system/bin/js_of_ocaml: No such file or directory

是否有人知道如何使所有这些包兼容?

早期:以下是安装npmnode之后以及opam switch reinstall system之前的编译错误:

:testweb $ ocamlfind ocamlc -package js_of_ocaml.ppx -linkpkg cubes.ml -o T
Failure("Ast_mapper: OCaml version mismatch or malformed input")
File "cubes.ml", line 1:
Error: Error while running external preprocessor
Command line: /Users/softtimur/.opam/system/lib/js_of_ocaml/./ppx_js '/var/folders/fn/0rmvqqbs4k76lg5g6b7kll100000gn/T/camlppxffe989' '/var/folders/fn/0rmvqqbs4k76lg5g6b7kll100000gn/T/camlppx02e06a'

另一种方式也出错:

:testweb $ ocamlfind ocamlc -package js_of_ocaml -syntax camlp4o -package js_of_ocaml.syntax -linkpkg -o cubes.byte cubes.ml
Fatal error: unknown C primitive `caml_is_printable'
File "cubes.ml", line 1:
Error: Error while running external preprocessor
Command line: camlp4 '-I' '/usr/local/lib/ocaml/camlp4' '-I' '/Users/softtimur/.opam/system/lib/js_of_ocaml' '-parser' 'o' '-parser' 'op' '-printer' 'p' 'pa_js.cmo'  'cubes.ml' > /var/folders/fn/0rmvqqbs4k76lg5g6b7kll100000gn/T/ocamlpp8b28e8

最初: 我最初的目标是编写和编译cubes.ml,以便1)它包装一个OCaml函数来创建一个可以在web中调用的JS函数; 2)可以在Linux下的命令行中测试OCaml函数和字节码。

cubes.ml如下:

let () =
  let oneArgument (a: int) = a + 100 in
  Js.Unsafe.global##.jsOneArgument := Js.wrap_callback oneArgument;
  print_string "hello\n";
  exit 0

然后,ocamlfind ocamlc -package js_of_ocaml.ppx -linkpkg cubes.ml -o T应生成T,以便./T返回hellojs_of_ocaml T -o cubes.js应生成cubes.js,以便jsOneArgument的{​​{1}}函数可以被其他JS或HTML文件调用。

在我搞砸包裹之前,cubes.js已退回./T,这就是我安装Unimplemented Javascript primitive caml_pure_js_expr!npm等等的原因......

1 个答案:

答案 0 :(得分:0)

我切换回OCaml 4.02.3:

opam switch 4.02.3

然后,

eval `opam config env`

然后,

opam install ppx_tools js_of_ocaml

因此,ocamlfind ocamlc -package js_of_ocaml.ppx -linkpkg cubes.ml -o T生成Tjs_of_ocaml T -o cubes.js生成cubes.jsnode cubes.js确实会返回hello

但是,./T仍会返回Unimplemented Javascript primitive caml_pure_js_expr!,我将打开另一个帖子......