This post is really informative on what I'm trying to achieve. I produced a simple HelloUnix binary.
$ echo 'main = putStrLn "Hello Unix"' > HelloUnix.hs
$ ghc -static --make HelloUnix.hs
Which created a HelloUnix
binary, I was hoping with the -static
flag everything is bundled up inside the binary so that all is needed to run the binary was the file itself. I transferred the binary to another unix machine, made sure that the file has the correct access privilege via chmod
. Ran the binary but this error showed up
bash: ./HelloUnix: cannot execute binary file
Any ideas on how to debug this?
EDIT: I'm currently trying to developing a distributed system, thus was hoping to just distribute the binary to target machines. I need a way to run the binary regardless of witch machine it's running on, that's the target anyways.
EDIT2: Source machine:
mike@mike-1215B:~/Haskell_Program/SmallApp/HelloUnix$ uname -a
Linux mike-1215B 3.0.0-13-generic #22-Ubuntu SMP Wed Nov 2 13:27:26 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
mike@mike-1215B:~/Haskell_Program/SmallApp/HelloUnix$ file HelloUnix
HelloUnix: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xa44cf0e797cd629e0add59722d51d2b20e00fad8, not stripped
mike@mike-1215B:~/Haskell_Program/SmallApp/HelloUnix$ ldd HelloUnix
linux-vdso.so.1 => (0x00007fff8404f000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fa918584000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fa91837c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa918081000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa917e79000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa917c75000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa9178b5000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa917698000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa918810000)
Remote machine 1:
[hchiao@rimmer] hchiao [1:59] uname -a
SunOS rimmer 5.9 Generic_122301-48 i86pc i386 i86pc
[hchiao@rimmer] hchiao [1:60] file HelloUnix
HelloUnix: ELF 64-bit LSB executable Version 1, dynamically linked, not stripped
Remote machine 2:
ubuntu@ip-10-240-88-224:~/cloud-haskell$ uname -a
Linux ip-10-240-88-224 3.2.0-36-virtual #57-Ubuntu SMP Tue Jan 8 22:21:19 UTC 2013 i686 i686 i386 GNU/Linux
ubuntu@ip-10-240-88-224:~/cloud-haskell$ file HelloUnix
HelloUnix: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xa44cf0e797cd629e0add59722d51d2b20e00fad8, not stripped
EDIT3: I'm now compiling the code in machine 2 and trying to run the binary in machine 1. I assume because both of them are i386 so the binary should be able to run on the other machine. However I'm getting this error:
HelloUnix: Cannot find /lib/ld-linux.so.2
Killed
I think this is telling me that a library (ld-linux.so.2
) the binary depend on (dynamic linking maybe?) is not in my target machine. I'm a little bit confused on what did the flag -static
do? I assumed with the flag, ALL dependencies would be bundled up in the binary. What would be the best way to make Haskell code portable?
If you are targeting the same architecture, it should work without any fuss (so long as necessary data files are also distributed).
If you are targeting a different architecture, as in your case, you need to cross-compile for the target platform; see the GHC wiki.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With