Compilation of 'Hello World' gives likely wrong machine code

Im on Debian GNU/Linux 9 (stretch) 64-bit with OCaml version 4.05.0 and I want to compile the following file into machine code using ocamlopt. To be more precise I have a .ml filethat which contains

print_string “Hello world!\n”;;

but is otherwise empty. I cd into, say …/folder than run

xx~$ ocamlopt …/folder/

and I get a file helloworld.o … On debian I chmod this file to be executeable. I execute the file

xx~$ …/folder/helloworld.o

and I get the error massage:

bash: …/folder/hello_world.o: cannot execute binary file: Exec format error

I think this means that the machine code is for another machine. Maybe a 64bit/32bit mismatch. I don’t know. Am I doing something wrong?

Note: Since I needed the latest Ocaml version, which is not in the debian repository, I might have installed a 32bit version. Can I check that?

The .o file is not an executable file, it’s a C object file. You need to run the a.out file that was produced in the directory.


Oh… my mistake. Tanks

Since you did not specify the executable you want to be generated (option -o), the default a.out should be in the same directory.

Run it.

ocamlc -config | grep architecture maybe?

Check the current working directory of where you invoked the command (for that reason it may be better to use the -o to specify the name and location of the executable to produce).

1 Like

Problem solved. Thanks