4

I'm trying to make an audio file I create slow down using SoX, and although I can easily compile the source files on the linux machine I use regularly, I need to transfer the binary to another linux machine with limited permissions and memory. I tried to copy the binary from the usr/local/bin folder on my machine to the other one and it could not find function references.

Is there a standard way to compile binaries with no dependencies, and if not, how do I set up the SoX binary so that it sees the correct dependencies when I only have write privileges in a temp folder?

3
  • Google for "static linking", IIRC it's just a matter of adding -static to your LDFLAGS (assuming you have a project with a standard-ish Makefile).
    – tripleee
    Commented Jan 11, 2012 at 7:29
  • Add to the previous: network-theory.co.uk/docs/gccintro/gccintro_25.html
    – tripleee
    Commented Jan 11, 2012 at 7:37
  • You can tell the binary where to look for shared libraries by setting the LD_LIBRARY_PATH environment variable. Should be easier than recompiling.
    – Jan Hudec
    Commented Jan 11, 2012 at 7:48

2 Answers 2

3

You can compile, adding the -static flag to the compilation options in the Makefile. But be aware of any differences in glibc versions between your two (or more) Linux workstations. You want to make sure that you compile on (or target for) the workstation with the older (or oldest) kernel, or your binary may not work due to dependencies on a newer kernel, which cannot be met by an older installation of Linux. So: basically, compile on your oldest machine for better results.

1
  • I'm not sure that I would recommend statically linking your own program. On my Debian/Sid distributions, I have more than 700 programs and only one is statically linked. At least, I don't recommend statically linking core system libraries like libc, libm, libdl ... I believe that distributions have a package manager for good reasons! Commented Jan 11, 2012 at 20:54
2

The most important thing you need to generate executables without dependencies is the static version of all libraries this executable will use. Usually, libraries are shares as well, meaning if they need to call another library's functions, they use shared linking. To not get 2nd-grade dependencies you need to compile all required libraries statically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.