4

After installing npm and node, compiling OCaml files with js_of_ocaml gave errors, thus I did 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

Then, i realized ocamlfind did not work anymore:

: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 gives v6.1.0; npm --version gives 3.8.6; ocaml -version gives The OCaml toplevel, version 4.03.0. js_of_ocaml --version was 2.7, but after the opam swtich reinstall system, it gives -bash: /Users/softtimur/.opam/system/bin/js_of_ocaml: No such file or directory.

Does anyone know what to do to make all these packages compatible?


Earlier: Here were the compilation errors after installing npm and node, and before doing 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'

Another way also gave an error:

: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

Initially: My initial goal is to write and compile cubes.ml such that 1) it wraps an OCaml function to make a JS function that can be called in web; 2) the OCaml function and the bytecode can be tested in a command line under Linux.

cubes.ml is as follows:

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

Then, ocamlfind ocamlc -package js_of_ocaml.ppx -linkpkg cubes.ml -o T should generate T such that ./T should return hello. And js_of_ocaml T -o cubes.js should generate cubes.js such that the function jsOneArgument of cubes.js can well be called by other JS or HTML files.

Before I messed up the packages, ./T returned Unimplemented Javascript primitive caml_pure_js_expr!, that is why i installed npm, node, etc...

6
  • Isn't $ node cubes.js enough?
    – zakki
    May 17, 2016 at 8:15
  • do you mean run node cubes.js in the command line? could you please elaborate more?
    – SoftTimur
    May 17, 2016 at 17:22
  • Yes. node.js outputs hello in a command line under Linux.
    – zakki
    May 18, 2016 at 0:38
  • I see what you mean... please see my updates...
    – SoftTimur
    May 18, 2016 at 3:49
  • Perhaps a system compiler is updated when install node. opam switch reinstall system may be needed.
    – zakki
    May 18, 2016 at 9:27

1 Answer 1

0

I switched back to OCaml 4.02.3:

opam switch 4.02.3

Then,

eval `opam config env`

Then,

opam install ppx_tools js_of_ocaml

As a result, ocamlfind ocamlc -package js_of_ocaml.ppx -linkpkg cubes.ml -o T generates T, and js_of_ocaml T -o cubes.js generates cubes.js. node cubes.js does return hello.

However, ./T still returns Unimplemented Javascript primitive caml_pure_js_expr!, I am going to open another post for that...

2
  • Note that it should be eval `opam config env` (backquote) or eval $(opam config env) (alternate bash syntax), simple quotes won't do.
    – gasche
    Jun 16, 2016 at 12:20
  • eval $(opam env) does the job, too Apr 24, 2020 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.