Reputation: 5490
I have written a one-line OCaml program: print_string "hello world!\n"
in my Mac OS. Then I compiled it by ocamlopt -o test test.ml
, the generated test
works fine.
Then I scp this test
to my Ubuntu & Nginx server, where OCaml is not installed. I launched ./test
, and got an error: -bash: ./code: cannot execute binary file: Exec format error
.
So do I have to install OCaml on the server, and compile my program over there? Isn't it possible to compile my program in Mac OS in a certain way such that the executable alone could run in a Ubuntu server?
Upvotes: 1
Views: 279
Reputation: 66818
Executable (binary) formats are not portable across systems, no. ocamlopt produces a format that is native to the system on which you do the compilation, and you shouldn't expect it to run on any other system unless it is of identical type.
You can get portability by compiling to bytecodes instead (using ocamlc rather than ocamlopt). Bytecode executables run more slowly, however.
Upvotes: 1