1

I have a bytecode, which worked previously well. Today, I'm trying to run it, I get an error the file './analyze' has not the right magic number: expected Caml1999X029, got Caml1999X023.

I try to switch OCaml version from 4.12.0 e.g., to 4.07.0 which might be the version when I built the bytecode. I still get the same error when running the bytecode.

Does anyone know how I could run this bytecode correctly?

SoftTimur
  • 5,630
  • 38
  • 140
  • 292
  • Not specific to OCaml, but [this post](https://stackoverflow.com/questions/514371/whats-the-bad-magic-number-error) may be instructive. – Chris Sep 25 '21 at 15:55
  • Previously, to compile the bytecode, I needed to install pacakges like `js_of_ocaml-ppx`. Now, since I have already the bytecode, after `opam switch 4.07.0`, do i still need to install other packages to execute the bytecode? – SoftTimur Sep 25 '21 at 20:40

2 Answers2

2

The error message looks extremely reasonable, which suggests that it is probably telling you what you need to know if you only knew what it meant :-) I don't know the structure of the bytecode magic numbers but it looks like a small difference.

You might try a few different versions of OCaml until its ocamlc generates the same magic number as your bytecode file. You can see the magic number of a bytecode file using dd (sorry I can't think of an easier way):

$ echo $(dd bs=12 count=1 if=m.cmo 2>/dev/null)
Caml1999O027

As you can see my OCaml version (4.10.0) is generating a different magic number from either of the two you're seeing.

Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108
1

(Re-posting as an answer what I wrote in comments.)

According to compiler docs, the part of the magic number after X is a number which grows monotonically with versions of the compiler. So, to find out what was the version of OCaml when Caml1999X023 was in use, you can try running your bytecode against various versions of OCaml, by dichotomy; or you can reverse-engineer the compiler by looking at the history of this source file or that one, which is where the magic number is set (I searched for the word ”magic” with the GitHub search bar).

I did it for you: looks like your magic number has been introduced by these 2 commits in April 2018: 1, 2. According to the description of the first one, your version is 4.07.0 — which is consistent with OCaml’s timeline.

I can’t tell why trying this version failed for you. I don’t know the answer to your question about js_of_ocaml-ppx (in comments).

Maëlan
  • 3,586
  • 1
  • 15
  • 35