How to compile a static binary bitcoind in Ubuntu #3781

issue bitcoinder openend this issue on March 2, 2014
  1. bitcoinder commented at 6:27 pm on March 2, 2014: none

    hi, i complied a bitcoind in Ubuntu Dektop 64bit 12.04.4 ./autogen.sh ./configure make sudo make install completed and works well in Ubuntu

    i moved this bitcoind into a Centos 64bit 6.5, ran it and some errors came out ./bitcoind: /lib64/libc.so.6: version `GLIBC_2.14’ not found (required by ./bitcoind) linux-vdso.so.1 => (0x00007fffa7dff000) libboost_system.so.1.46.1 => not found libboost_filesystem.so.1.46.1 => not found libboost_program_options.so.1.46.1 => not found libboost_thread.so.1.46.1 => not found libdb_cxx-4.8.so => not found libssl.so.1.0.0 => not found libcrypto.so.1.0.0 => not found libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fbe9c216000) libm.so.6 => /lib64/libm.so.6 (0x00007fbe9bf92000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fbe9bd7c000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fbe9bb5e000) libc.so.6 => /lib64/libc.so.6 (0x00007fbe9b7ca000) /lib64/ld-linux-x86-64.so.2 (0x0000003dc6000000)

    i think all *.so lib required need to be compiled together with the bitcoind binnary, but how? i tried ./autogen.sh ./configure LDFLAGS=-static make sudo make install completed but still doesn’t work in Centos, same error

    the bitcoind in https://bitcoin.org/bin/0.8.6/bitcoin-0.8.6-linux.tar.gz however works well in both Centos and Ubuntu another question, why it has only 6.6MB size? my bicoind has 56MB, i am not good at linux, please help in details

  2. FelixWeis commented at 8:56 pm on March 2, 2014: contributor

    To reduce the size of the binary, you can strip the debug symbols by running

    0strip src/bitcoind src/bitcoin-cli
    

    after make

  3. laanwj commented at 6:18 am on March 3, 2014: member
    Use the gitian linux build, it will produce a static executable such as the one packaged and released.
  4. jgarzik commented at 1:00 pm on March 3, 2014: contributor

    @laanwj Just checking… is that verified with “ldd $executable”? Looking at the 0.9.0rc2 builds, they are not static.

    Crowd: I did the same. I built a completely static executable. Usually there is a configure argument such as “–enable-static” to assist this.

    My steps on Ubuntu:

    1. Add -static to CXXFLAGS
    2. Add -static to LDFLAGS
    3. Add -L/usr/lib/x86_64-linux-gnu to LDFLAGS.
    4. Compile proceeds just fine until the link step, which fails.
    5. Manually execute the link step for each executable (shown with “make V=1”), removing “-L/usr/lib” from the link command line.

    We force /usr/lib into LDFLAGS somewhere, and this is incorrect.

  5. laanwj commented at 1:10 pm on March 3, 2014: member

    Yes, that has been extensively verified. Some libraries are statically linked but not all. That’s a conscious choice. For example the libc(++) is not statically linked as this is generally discouraged. Also (in the case of bitcoin-qt) Qt is not statically linked because that would foil integration into the desktop. On the other hand OpenSSL is statically linked to avoid problems with distributions that don’t package ECDSA support, same for boost because those shared libraries are not usually available.

    So that leaves only ‘base OS’ direct dependencies. For bitcoind these are:

    00x00000001 (NEEDED)                     Shared library: [librt.so.1]
    10x00000001 (NEEDED)                     Shared library: [libstdc++.so.6]
    20x00000001 (NEEDED)                     Shared library: [libm.so.6]
    30x00000001 (NEEDED)                     Shared library: [libgcc_s.so.1]
    40x00000001 (NEEDED)                     Shared library: [libpthread.so.0]
    50x00000001 (NEEDED)                     Shared library: [libc.so.6]
    

    For bitcoin-qt these are:

    00x00000001 (NEEDED)                     Shared library: [librt.so.1]
    10x00000001 (NEEDED)                     Shared library: [libQtGui.so.4]
    20x00000001 (NEEDED)                     Shared library: [libQtNetwork.so.4]
    30x00000001 (NEEDED)                     Shared library: [libQtCore.so.4]
    40x00000001 (NEEDED)                     Shared library: [libQtDBus.so.4]
    50x00000001 (NEEDED)                     Shared library: [libpthread.so.0]
    60x00000001 (NEEDED)                     Shared library: [libstdc++.so.6]
    70x00000001 (NEEDED)                     Shared library: [libm.so.6]
    80x00000001 (NEEDED)                     Shared library: [libgcc_s.so.1]
    90x00000001 (NEEDED)                     Shared library: [libc.so.6]
    

    (readelf -d output here as ldd also shows indirect dependencies)

  6. jgarzik commented at 1:23 pm on March 3, 2014: contributor

    Ok, then it is incorrect to say “Use the gitian linux build, it will produce a static executable”

    It produces a dynamic executable, with some libs linked statically.

  7. laanwj commented at 1:26 pm on March 3, 2014: member
    Yes I think I was confused with the windows build which is fully static.
  8. bitcoinder commented at 1:49 pm on March 3, 2014: none

    @laanwj [Use the gitian linux build, it will produce a static executable such as the one packaged and released.]

    thanks, could you tell me what is gitian linux build and how to do it? i want a static executable like the released sorry i am noob

  9. bitcoinder commented at 1:53 pm on March 3, 2014: none
    @FelixWeis thanks, i will try it later
  10. bitcoinder commented at 1:59 pm on March 3, 2014: none

    i also noticed that there are two ways to build bitcoind, one is mentioned in the post, another one is cd bitcoin-0.8.6-linux/src/src make STATIC=1 -f makefile.unix bitcoind USE_UPNP=

    what is the difference? the second way requires a bitcoin-0.8.6-linux.tar.gz, the first way requires a source code zip file https://github.com/bitcoin/bitcoin/archive/master.zip

  11. laanwj commented at 2:37 pm on March 3, 2014: member

    Building a fully static executable may also get in the way of some hardening options such as address space randomization (ie -fPIE/-pie).

    No clue how the -L/usr/lib ends up in the linker options, I get it here too, my guess would be that it comes from one of the pkgconfig files and/or the boost detection. @bitcoinder As for using gitian to build, see for example Gavin’s guide: http://gavintech.blogspot.nl/2014/02/gitian-building-bitcoin-releases.html

  12. bitcoinder commented at 3:00 pm on March 3, 2014: none

    is https://bitcoin.org/bin/0.8.6/bitcoin-0.8.6-linux.tar.gz a fully static executable bin? does this way work? cd bitcoin-0.8.6-linux/src/src make STATIC=1 -f makefile.unix bitcoind USE_UPNP=

    because i found some code looks like a static switch in makefile.unix: LMODE = dynamic LMODE2 = dynamic ifdef STATIC LMODE = static ifeq (${STATIC}, all) LMODE2 = static endif else TESTDEFS += -DBOOST_TEST_DYN_LINK endif

    etc..

  13. laanwj commented at 5:49 pm on May 2, 2014: member

    I’ve written down steps to do a gitian build from scratch in a VM here: https://github.com/bitcoin/bitcoin/blob/master/doc/gitian-building.md

    Apart from that I think the question has been answered in all possible ways, so I’m closing this.

  14. laanwj closed this on May 2, 2014

  15. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-19 06:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me