After #26645, this change is required to be able to #include clientversion.h in the libbitcoinconsensus code without dependency on util/translation.h.
Steps to reproduce the problem
To demonstrate the problem, let's consider the x86_64-w64-mingw32 platform as it guarantees that all symbols are defined in a library:
$ make -C depends HOST=x86_64-w64-mingw32 NO_QT=1 NO_WALLET=1 NO_NATPMP=1 NO_UPNP=1 NO_ZMQ=1
$ ./autogen.sh && ./configure CONFIG_SITE=$PWD/depends/x86_64-w64-mingw32/share/config.site && make clean
And now, let's apply a diff as follows:
--- a/src/script/bitcoinconsensus.cpp
+++ b/src/script/bitcoinconsensus.cpp
@@ -8,6 +8,7 @@
#include <primitives/transaction.h>
#include <pubkey.h>
#include <script/interpreter.h>
+#include <util/check.h>
#include <version.h>
namespace {
@@ -25,7 +26,7 @@ public:
void read(Span<std::byte> dst)
{
if (dst.size() > m_remaining) {
- throw std::ios_base::failure(std::string(__func__) + ": end of data");
+ throw std::ios_base::failure(STR_INTERNAL_BUG("end of data"));
}
if (dst.data() == nullptr) {
The resulted code fails to compile:
$ make
...
CXXLD libbitcoinconsensus.la
/usr/bin/x86_64-w64-mingw32-ld: script/.libs/libbitcoinconsensus_la-bitcoinconsensus.o:bitcoinconsensus.cpp:(.text+0x1db): undefined reference to `StrFormatInternalBug[abi:cxx11](char const*, char const*, int, char const*)'
...
Obviously, the util/check.cpp needs to be added to the library sources:
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -972,6 +972,7 @@ lib_LTLIBRARIES += $(LIBBITCOINCONSENSUS)
include_HEADERS = script/bitcoinconsensus.h
libbitcoinconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_la_SOURCES) $(libbitcoin_consensus_a_SOURCES)
+libbitcoinconsensus_la_SOURCES += util/check.cpp
libbitcoinconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1)
Now, a linker complains about another symbol:
$ make
...
CXXLD libbitcoinconsensus.la
/usr/bin/x86_64-w64-mingw32-ld: util/.libs/libbitcoinconsensus_la-check.o:check.cpp:(.text+0x8c): undefined reference to `FormatFullVersion[abi:cxx11]()'
...
which is defined in the clientversion.cpp:
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -972,6 +972,7 @@ lib_LTLIBRARIES += $(LIBBITCOINCONSENSUS)
include_HEADERS = script/bitcoinconsensus.h
libbitcoinconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_la_SOURCES) $(libbitcoin_consensus_a_SOURCES)
+libbitcoinconsensus_la_SOURCES += clientversion.cpp util/check.cpp
libbitcoinconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1)
This time a linker error is:
$ make
...
CXXLD libbitcoinconsensus.la
/usr/bin/x86_64-w64-mingw32-ld: .libs/libbitcoinconsensus_la-clientversion.o:clientversion.:(.rdata$.refptr._Z17G_TRANSLATION_FUNB5cxx11[.refptr._Z17G_TRANSLATION_FUNB5cxx11]+0x0): undefined reference to `G_TRANSLATION_FUN[abi:cxx11]'
...
which is supposed to be solved by this PR.
See #26504.
The last time those functions were moved in #24409.