Linker error
Hi, first off I want to thank you for creating the awesome tutorial. I'm having a bit of trouble compiling the code on Ubuntu installed via Windows 10 bash. I've tried changing the compilation part to use 32 bit flags and 64 bit flags but have had no luck so far (in both nasm -elf64 and gcc -m32) This is what happens using the version on master right now:
nfgallimore@DESKTOP-DA4I93N:~/micro$ make
/usr/bin/env ocamlc -o micro unix.cma micro.ml
File "micro.ml", line 51, characters 53-69:
Warning 3: deprecated: String.lowercase
Use String.lowercase_ascii instead.
nfgallimore@DESKTOP-DA4I93N:~/micro$ ./micro examples/hello.mc
compiling examples/hello.mc
/usr/bin/ld: i386 architecture of input file `examples/hello.o' is incompatible with i386:x86-64 output
collect2: error: ld returned 1 exit status
nfgallimore@DESKTOP-DA4I93N:~/micro$
I'm sure this is something quite obvious. Thank you for the guide, it's very helpful because I want to use Ocaml for a compiler design course I am taking next semester.
@nfgallimore sure, thank you for reading my blog, now first of all in ubuntu you need to be able to compile 32-bit applications with gcc, to do that you need to install gcc-multilib
sudo apt-get install gcc-multilib
then in micro.ml on line 320 add -m32 flag to gcc compile command like so let _ = Sys.command ("gcc -m32 -o " ^ out ^ " " ^ out ^ ".o") in ()
Now recompile your micro compiler using make and try compiling example again, should work
Thanks for the reply @troydm
Here's what happened when I did that and tried to run the binary:
nfgallimore@DESKTOP-DA4I93N:~/micro/examples$ ./hello -bash: ./hello: cannot execute binary file: Exec format error
I tried following these steps, and I had previously tried adding the -m32 flag. I tried compiling it into 64 bit using nasm -elf64 as well but the assembly operations are not supported. What system did you compile this on?
@nfgallimore strange, should work, I've tried it on Ubuntu 16.04 LTS x86-64