Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker error #1

Open
nfgallimore opened this issue Jul 11, 2018 · 3 comments
Open

Linker error #1

nfgallimore opened this issue Jul 11, 2018 · 3 comments

Comments

@nfgallimore
Copy link

nfgallimore commented Jul 11, 2018

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.

@troydm
Copy link
Owner

troydm commented Jul 12, 2018

@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

@nfgallimore
Copy link
Author

nfgallimore commented Jul 13, 2018

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?

@troydm
Copy link
Owner

troydm commented Jul 14, 2018

@nfgallimore strange, should work, I've tried it on Ubuntu 16.04 LTS x86-64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants