0

I have a remote Unix server that I want to run various programs on. I can easily set up a local virtual machine running some flavour of Unix, on which I can compile my programs. The trouble is, it seems that moving a Unix program from one host to another always fails spectacularly. :-(

For example, I compiled test on an OpenSUSE 11.4 system, and tried to run it. It worked perfectly. But then I copied the compiled binary to a Debian 6.0.3 system, and now it refuses to run. Instead, I just get

test: error while loading shared libraries: libgmp.so.10: cannot open shared object file: No such file or directory

Presumably installing the compiler also installs all the dependencies - but only on the local machine. I would presumably have to somehow guess what dependencies I need to put on the remote machine.

On top of that, I don't have shell access to the remote machine. I only have FTP. So I can't install anything. I can only copy files to it. So I'm wondering whether I can just copy the necessary shared libraries to the same folder as the compiled binary. Would that work? Or would I have to do something more complex?

4

1 回答 1

1

I think your best bet, given the circumstances, is to compile a static binary; see the -static option of gcc. However, this has downsides and might not always work.

You could also try to copy the shared libraries, but then you need to instruct the dynamic loader to search for the libraries in the location where you added them (your binary will have to be linked with the -Wl,-rpath,/path/to/libs switch.

Try the -static first. It should be easier.

If you wanna take a deeper look into the issues of binary portability, check out sources like:

于 2012-07-19T12:49:48.520 回答