i'm trying to send a bash script file using ssh to my remote server but first i want to make it executable on my own machine which is arm64 and then send the .exe file to remote server but remote server arch is x86_64, how can i use the 'shc' command to produce a .exe file to be compatible with x86_64?
on my own machine
shc -f test.sh -o test
but on my ubuntu x86_64 can't execute it because it was compiled on a arm64 machine. is there any way to make it work on arm64 with shc?
I just installed shc
to see if I could solve your problem, but I wasn't able to get it to compile for a different architecture. I tried to compile the script for i386 with gcc -march=i386 foo.x.c
but it complained that i386 didn't support the x86_64 commands used. Normally I cross compile from a ./configure
script like this:
./configure \
--build=i386-pc-linux-gnu \
--host=i386-pc-linux-gnu \
--target=i386-pc-linux-gnu \
&& make -j 8 \
&& make install
I'm not very familiar with using gcc
directly to cross-compile for another architecture, maybe someone else more familiar with cross-compiling can suggest how to use gcc
to compile for a different architecture.
I can see on my Ubuntu that there's a lot of packages for cross-compiler tools, such as alternate gcc
versions just for cross-compiling on various architectures including ARM64, but I don't know how to use them.
I can see from the shc
man page that it uses these environment variables:
CC : C compiler command [cc]
CFLAGS : C compiler flags [none]
LDFLAGS : Linker flags [none]
But I am not familiar with what would be put into these.
As an alternate workaround, rather than getting shc
to compile the script for another architecture, you could run shc
on that other architecture directly:
For example, you could use an ssh
command to connect to the destination computer, compile it there, then scp
the resulting file back to your end.
Another method would be to emulate the architecture locally using QEMU
or another emulator that supports the architecture. If you wanted to try that method, here's a guide: