Since the move to cmake, the kernel static library that is installed after a cmake --install build
is unusable. It basically lacks all symbols, besides those defined in the kernel library target. This was a problem before where some libtool and symbol visibility issues led to the libsecp static library having to be linked too. Additionally installing libsecp was easily done though, by changing to the secp256k1
directory and running make install
.
Previously, e.g. on the v28 release branch, configuring with --with-experimental-kernel-lib --disable-shared
, then doing a make install
and make install
in the secp256k1
directory provided working libraries. This could be verified by successfully compiling bitcoin-chainstate.cpp
without the build system:
0g++ -std=c++20 -o test_chainstate src/bitcoin-chainstate.cpp -I/home/drgrid/bitcoin/src -L/usr/local/lib -lbitcoinkernel -lsecp256k1
When the same is attempted on current master, configuring with -DBUILD_KERNEL_LIB=ON -DBUILD_SHARRED_LIBS=OFF
, then doing a cmake --install build
, will make the same g++ command error with e.g:
0/usr/bin/ld: ./build/src/kernel/./build/src/kernel/./src/hash.cpp:89:(.text+0x2f6): undefined reference to `CSHA256::Write(unsigned char const*, unsigned long)'
1/usr/bin/ld: ./build/src/kernel/./build/src/kernel/./src/hash.cpp:89:(.text+0x306): undefined reference to `CSHA256::Finalize(unsigned char*)'
When attempting to compile bitcoin-chainstate
through cmake, the following is visible in the logs, which enumerates the missing libraries:
0[100%] Linking CXX executable bitcoin-chainstate
1cd /home/drgrid/bitcoin/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/bitcoin-chainstate.dir/link.txt --verbose=1
2/usr/bin/clang++ -O2 -g -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wl,-z,relro -Wl,-z,now -Wl,-z,separate-code -fPIE -pie "CMakeFiles/bitcoin-chainstate.dir/bitcoin-chainstate.cpp.o" -o bitcoin-chainstate kernel/libbitcoinkernel.a crypto/libbitcoin_crypto.a crypto/libbitcoin_crypto_sse41.a crypto/libbitcoin_crypto_avx2.a crypto/libbitcoin_crypto_x86_shani.a ../libleveldb.a ../libcrc32c.a ../libcrc32c_sse42.a secp256k1/src/libsecp256k1.a
Evidently cmake is capable of correctly calculating the required libraries within the Bitcoin Core cmake project, but it is not clear to me what the best approach towards solving this for the installed library might be. Cmake seems to be inherently incapable of combining static libraries. A potential solution for this could be adding an ar
hack that manually “re-ars” the archives into a single, static kernel library (though it is not clear how to recursively calculate the required libraries). Another solution could also be shipping all these small, additional libraries in a separate install step.