0

Is it possible to build a binary with dependent .so files included so that the binary can be built once and used on machines with the same hardware and OS, without them having the .so files?

For example, I am building curl with nghttp2. I do

 ./configure --with-nghttp2=/usr/local

Then I ran make. I got the curl binary. When I copy over this binary on to another machine and try to run it, it says

./curl: error while loading shared libraries: libnghttp2.so.14: cannot open shared object file: No such file or directory

I also tried running make as follows:

make SHARED=0 CFLAGS='-static'

I still get that same error.

  • You can doing static linking, but how effective it is will depend on the specific situation. – Faheem Mitha Oct 29 '15 at 18:33
  • I dont't care about the size of the binary I end up with. Also the machines where I would be using the built binary would be same architecture and OS as the machine where I build it. Just that on those machine I would't be able to install any libraries. Hence want to use this approach. – RBK Oct 30 '15 at 0:32
  • Check this question: Static link of shared library function in gcc – Andrew Kozlov Oct 30 '15 at 6:46
1

Depend .so files can be in form of shared objects (they are, .so files) or .a files aka static objects. You can rebuild nghttp2 and pass --disable-shared flag to it's configure. Then you can try to reconfigure and rebuild curl as usual.

The point is to be sure that you have only static .a object in /usr/local/lib to link curl with.

Do not forget to check that /usr/local/lib does not contain .so version of nghttp2! (Or you can specify another --prefix= to experiment with. You even can install anything into /tmp or your $HOME and play with that locally created tree)

Note that this will not eliminate other dependencies from curl, since it is large project that depends on code form third parties. It can even depend on itself, libcurl. You can pass --disable-shared flag to it to build only it's static version. At end, run readelf -d /path/to/your/curl | fgrep NEEDED to see it's full dependencies!

  • Thanks, using --disable-shared and building nghttp2 and then building curl with --disable-shared, I got a binary which I could use on other machines too. I saw the other dependancies and they were libc, libssl libz & libcrypto. I think the machines I deployed this binary had the correct versions of these and so the binary ran without issues. – RBK Oct 30 '15 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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