can't run bin file generated from ubuntu(x86_64) in mac (x86_64)

947 views
Skip to first unread message

Zhong Lee

unread,
Nov 18, 2013, 5:03:52 AM11/18/13
to golan...@googlegroups.com
ubuntu: uname -a:

Linux precise64 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

mac: uname -a:

Darwin limboy.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64

so they are both x86_64, and i write a simple 'hello.go' in ubuntu, and cp the bin file to mac, but when executing, output the error:

./hello: cannot execute binary file


Niklas Schnelle

unread,
Nov 18, 2013, 5:12:13 AM11/18/13
to golan...@googlegroups.com
Go is compiled down to binary exectuables and since Mac OS X is not Linux they don't share binary compatibility and unlike with FreeBSD Mac OS X
doesn't have a compatibility layer and it also uses ca completely different format (Mach-O vs ELF).
You need to compile for Mac OS X if you want to run it there, the easiest way to do this is to install Go on Mac OS X,
you can however generate Mac OS X binaries on Linux using cross compilation.

Dave Cheney

unread,
Nov 18, 2013, 5:12:03 AM11/18/13
to Zhong Lee, golang-nuts
try

file ./hello

I think you'll find that that binary is built for linux systems, not
darwin. The fact that they are both amd64 is not sufficient.

Please read, http://dave.cheney.net/2013/07/09/an-introduction-to-cross-compilation-with-go-1-1
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Jan Mercl

unread,
Nov 18, 2013, 5:11:59 AM11/18/13
to Zhong Lee, golang-nuts
It's not expected to work that way. Wrt the binary: Compatible
architectures, incompatible operating systems.

-j

Zhong Lee

unread,
Nov 18, 2013, 5:47:51 AM11/18/13
to golan...@googlegroups.com, Zhong Lee
@Niklas Schnelle @Dave Cheney @Jan Mercl  thank you guys, i think i get the point. :)
Reply all
Reply to author
Forward
0 new messages