camlp4o is not a bytecode executable file (error on osx)

1.8k Views Asked by At

I had ocaml 3.12, didn't used for a year and now upgraded to 4.03 from git (compiled myself). I saw some comments on the internet that this version does not include camlp4o, mine is from 2010 when i didn't even had ocaml installed. The problem is that i can't compile a program because of it. I went on the harddrive to that file and i don't see anything wrong, but if i try to execute from Terminal i get this

79-116-202-72:ocaml Cristi$ camlp4o
Fatal error: the file '/usr/local/bin/camlp4o' is not a bytecode executable file

The same for the other caml files. Hoping that this will fix my problem how can i update them? I'm using osx. Thanks!

2

There are 2 best solutions below

1
On BEST ANSWER

From OCaml 4.02.0 (not released yet!), CamlP4 is dropped from the compiler source code. If you upgrade your OCaml installation from 4.01.0 or prior to 4.02.0 or later, the following thing may happen:

  • The OCaml compiler toolset of the older version are overwritten by the newer versions including the bytecode interpreter ocamlrun, except Camlp4.
  • CamlP4 byte code executables (camlp4o, camlp4of, ...) of the older version remain as they are.

In this situation, if you type camlp4o, then its bytecode for the older runtime is executed by the newer ocaml bytecode interpreter ocamlrun. Unfortunately, it does not understand the older bytecode. (I guess it is intentional.)

The fix is to install CamlP4 by your new compiler. The source code is now available at https://github.com/ocaml/camlp4 .

There are some other possible senarios. For example, if you install OCaml 4.01.0 by hand, then install OPAM using 4.01.0, then change your compiler to 4.02.0 by opam switch. In this case the fix is also to install CamlP4 using the new compiler by opam install camlp4 command.

2
On
  1. It's better to use OCaml 4.02 because it will be released this summer. 4.03 is to young now
  2. Its better to install ocaml using Opam, to be more concretely by using opam switch -a and opam switch compilername. Camlp4 should be isntalled via Opam too.
  3. there is possibility that you execute camp4o when you have bytecode interpreter for newer OCaml bytecode version. That's why it doesn't recognize it correctly.