How to run ghc compilation on other machines?

This post is really informative of what I'm trying to achieve. I created a simple HelloUnix binary.

$ echo 'main = putStrLn "Hello Unix"' > HelloUnix.hs $ ghc -static --make HelloUnix.hs 

What created the HelloUnix binary, I was hoping the -static flag would all link inside the binary, so all that was needed to run the binary was the file itself. I transferred the binary to another unix machine, making sure that the file has the correct access privilege via chmod . Called binary, but this error appeared

 bash: ./HelloUnix: cannot execute binary file 

Any ideas on how to debug this?

EDIT: I'm currently trying to develop a distributed system, so I was hoping to just distribute the binaries to the target machines. I need a way to run the binary, even though it is running, which is the target anyway.

EDIT2: Source:

 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: Now I am compiling the code in machine 2 and trying to run the binary on machine 1. I assume that they are both i386, so the binary should work on another machine. However, I get this error:

 HelloUnix: Cannot find /lib/ld-linux.so.2 Killed 

I think this tells me that the library ( ld-linux.so.2 ) that the binary depends on (maybe dynamic linking?) Is not on my target machine. Am I a little confused about what the -static flag did? I assumed that with the flag all dependencies will be combined into a binary file. What would be the best way to make Haskell portable code?

+6
source share
1 answer

If you target the same architecture, it should work without any problems (provided that the necessary data files are also distributed).

If you target a different architecture, as in your case, you need to cross-compile for the target platform; see the GHC wiki .

+5
source

Source: https://habr.com/ru/post/944947/


All Articles