2016-05-16 96 views
4

安裝npmnode,編譯OCaml的文件與js_of_ocaml了錯誤後,因此我做了opam switch reinstall system使兼容ocaml的,camlp4,PPX,節點,js_of_ocaml,ocamlbuild

: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 --versionv6.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應返回hello。並且js_of_ocaml T -o cubes.js應該生成cubes.js,使得cubes.js的功能jsOneArgument可以很好地被其他JS或HTML文件調用。

之前我搞砸了包,./T回到Unimplemented Javascript primitive caml_pure_js_expr!,這就是爲什麼我安裝npmnode,等...

+0

是不是'$節點cubes.js'就夠了嗎? – zakki

+0

你的意思是在命令行中運行'node cubes.js'嗎?你能否詳細說明一下? – SoftTimur

+0

是的。 node.js在Linux下的命令行中輸出'hello'。 – zakki

回答

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生成T,並且js_of_ocaml T -o cubes.js生成cubes.jsnode cubes.js確實返回hello

然而,./T仍返回Unimplemented Javascript primitive caml_pure_js_expr!,我會打開另一個職位是...

+0

請注意它應該是''eval'opam config env''(反引號)或'eval $(opam config env)'(備用bash語法),簡單的引號不會。 – gasche

+0

確定...已更正... – SoftTimur