build: Extract the libbitcoinkernel library

I strongly recommend reviewing with the following git-diff flags:
  --patience --color-moved=dimmed-zebra

Extract out a libbitcoinkernel library linking in all files necessary
for using our consensus engine as-is. Link bitcoin-chainstate against
it.

See previous commit "build: Add example bitcoin-chainstate executable"
for more context.

We explicitly specify -fvisibility=default, which effectively overrides
the effects of --enable-reduced-exports since libbitcoinkernel requires
default symbol visibility

When compiling for mingw-w64, specify -static in both:

- ..._la_CXXFLAGS so that libtool will avoid building two versions of
  each object (one PIC, one non-PIC). We just need the one that is
  suitable for static linking.
- ..._la_LDFLAGS so that libtool will create a static library.

If we don't specify this, then libtool will prefer the non-static PIC
version of the object, which is built with -DDLL_EXPORT -DPIC for
mingw-w64 targets. This can cause symbol resolution problems when we
link this library against an executable that does specify -all-static,
since that will be built without the -DDLL_EXPORT flag.

Unfortunately, this means that for mingw-w64 we can only build a static
version of the library for now. This will be fixed.

However, on other targets, the shared library creation works fine.

-----

Note to users: You need to either specify:

  --enable-experimental-util-chainstate

or,

  --with-experimental-kernel-lib

To build the libbitcionkernel library. See the configure help for more
details.

build shared libbitcoinkernel where we can
pull/24322/head
Carl Dong 3 years ago
parent 1df44dd20c
commit 26b2e7ffb3

@ -663,6 +663,12 @@ AC_ARG_WITH([libs],
[build_bitcoin_libs=$withval],
[build_bitcoin_libs=yes])
AC_ARG_WITH([experimental-kernel-lib],
[AS_HELP_STRING([--with-experimental-kernel-lib],
[build experimental bitcoinkernel library (default is to build if we're building libraries and the experimental build-chainstate executable)])],
[build_experimental_kernel_lib=$withval],
[build_experimental_kernel_lib=auto])
AC_ARG_WITH([daemon],
[AS_HELP_STRING([--with-daemon],
[build bitcoind daemon (default=yes)])],
@ -1657,15 +1663,23 @@ AM_CONDITIONAL([BUILD_BITCOIN_UTIL], [test $build_bitcoin_util = "yes"])
AC_MSG_RESULT($build_bitcoin_util)
AC_MSG_CHECKING([whether to build experimental bitcoin-chainstate])
AM_CONDITIONAL([BUILD_BITCOIN_CHAINSTATE], [test $build_bitcoin_chainstate = "yes"])
if test "$build_experimental_kernel_lib" = "no"; then
AC_MSG_ERROR([experimental bitcoin-chainstate cannot be built without the experimental bitcoinkernel library. Use --with-experimental-kernel-lib]);
else
AM_CONDITIONAL([BUILD_BITCOIN_CHAINSTATE], [test $build_bitcoin_chainstate = "yes"])
fi
AC_MSG_RESULT($build_bitcoin_chainstate)
AC_MSG_CHECKING([whether to build libraries])
AM_CONDITIONAL([BUILD_BITCOIN_LIBS], [test $build_bitcoin_libs = "yes"])
if test "$build_bitcoin_libs" = "yes"; then
AC_DEFINE([HAVE_CONSENSUS_LIB], [1], [Define this symbol if the consensus lib has been built])
AC_CONFIG_FILES([libbitcoinconsensus.pc:libbitcoinconsensus.pc.in])
fi
AM_CONDITIONAL([BUILD_BITCOIN_KERNEL_LIB], [test "$build_experimental_kernel_lib" != "no" && ( test "$build_experimental_kernel_lib" = "yes" || test "$build_bitcoin_chainstate" = "yes" )])
AC_MSG_RESULT($build_bitcoin_libs)
AC_LANG_POP

@ -29,6 +29,7 @@ LIBBITCOIN_NODE=libbitcoin_node.a
LIBBITCOIN_COMMON=libbitcoin_common.a
LIBBITCOIN_CONSENSUS=libbitcoin_consensus.a
LIBBITCOIN_CLI=libbitcoin_cli.a
LIBBITCOIN_KERNEL=libbitcoin_kernel.a
LIBBITCOIN_UTIL=libbitcoin_util.a
LIBBITCOIN_CRYPTO_BASE=crypto/libbitcoin_crypto_base.la
LIBBITCOINQT=qt/libbitcoinqt.a
@ -40,6 +41,9 @@ endif
if BUILD_BITCOIN_LIBS
LIBBITCOINCONSENSUS=libbitcoinconsensus.la
endif
if BUILD_BITCOIN_KERNEL_LIB
LIBBITCOINKERNEL=libbitcoinkernel.la
endif
if ENABLE_WALLET
LIBBITCOIN_WALLET=libbitcoin_wallet.a
LIBBITCOIN_WALLET_TOOL=libbitcoin_wallet_tool.a
@ -798,8 +802,39 @@ bitcoin_util_LDADD = \
#
# bitcoin-chainstate binary #
bitcoin_chainstate_SOURCES = \
bitcoin-chainstate.cpp \
bitcoin_chainstate_SOURCES = bitcoin-chainstate.cpp
bitcoin_chainstate_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
bitcoin_chainstate_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
bitcoin_chainstate_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
bitcoin_chainstate_LDADD = $(LIBBITCOINKERNEL)
#
# bitcoinkernel library #
if BUILD_BITCOIN_KERNEL_LIB
lib_LTLIBRARIES += $(LIBBITCOINKERNEL)
libbitcoinkernel_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) $(PTHREAD_FLAGS)
libbitcoinkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1)
libbitcoinkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)
# libbitcoinkernel requires default symbol visibility, explicitly specify that
# here so that things still work even when user configures with
# --enable-reduce-exports
#
# Note this is a quick hack that will be removed as we incrementally define what
# to export from the library.
libbitcoinkernel_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -fvisibility=default
# TODO: For now, Specify -static in both CXXFLAGS and LDFLAGS when building for
# windows targets so libtool will only build a static version of this
# library. There are unresolved problems when building dll's for mingw-w64
# and attempting to statically embed libstdc++, libpthread, etc.
if TARGET_WINDOWS
libbitcoinkernel_la_LDFLAGS += -static
libbitcoinkernel_la_CXXFLAGS += -static
endif
libbitcoinkernel_la_SOURCES = \
kernel/bitcoinkernel.cpp \
arith_uint256.cpp \
blockfilter.cpp \
@ -879,19 +914,11 @@ bitcoin_chainstate_SOURCES = \
validationinterface.cpp \
versionbits.cpp \
warnings.cpp
bitcoin_chainstate_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
bitcoin_chainstate_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
bitcoin_chainstate_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
bitcoin_chainstate_LDADD = \
$(LIBBITCOIN_CRYPTO) \
$(LIBUNIVALUE) \
$(LIBSECP256K1) \
$(LIBLEVELDB) \
$(LIBMEMENV)
# Required for obj/build.h to be generated first.
# More details: https://www.gnu.org/software/automake/manual/html_node/Built-Sources-Example.html
bitcoin_chainstate-clientversion.$(OBJEXT): obj/build.h
libbitcoinkernel_la-clientversion.l$(OBJEXT): obj/build.h
endif # BUILD_BITCOIN_KERNEL_LIB
#
# bitcoinconsensus library #

Loading…
Cancel
Save