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:
0$ make -C depends HOST=x86_64-w64-mingw32 NO_QT=1 NO_WALLET=1 NO_NATPMP=1 NO_UPNP=1 NO_ZMQ=1
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:
0--- a/src/script/bitcoinconsensus.cpp
1+++ b/src/script/bitcoinconsensus.cpp
2@@ -8,6 +8,7 @@
3 #include <primitives/transaction.h>
4 #include <pubkey.h>
5 #include <script/interpreter.h>
6+#include <util/check.h>
7 #include <version.h>
8
9 namespace {
10@@ -25,7 +26,7 @@ public:
11 void read(Span<std::byte> dst)
12 {
13 if (dst.size() > m_remaining) {
14- throw std::ios_base::failure(std::string(__func__) + ": end of data");
15+ throw std::ios_base::failure(STR_INTERNAL_BUG("end of data"));
16 }
17
18 if (dst.data() == nullptr) {
The resulted code fails to compile:
0$ make
1...
2 CXXLD libbitcoinconsensus.la
3/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*)'
4...
Obviously, the util/check.cpp
needs to be added to the library sources:
0--- a/src/Makefile.am
1+++ b/src/Makefile.am
2@@ -972,6 +972,7 @@ lib_LTLIBRARIES += $(LIBBITCOINCONSENSUS)
3
4 include_HEADERS = script/bitcoinconsensus.h
5 libbitcoinconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_la_SOURCES) $(libbitcoin_consensus_a_SOURCES)
6+libbitcoinconsensus_la_SOURCES += util/check.cpp
7
8 libbitcoinconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
9 libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1)
Now, a linker complains about another symbol:
0$ make
1...
2 CXXLD libbitcoinconsensus.la
3/usr/bin/x86_64-w64-mingw32-ld: util/.libs/libbitcoinconsensus_la-check.o:check.cpp:(.text+0x8c): undefined reference to `FormatFullVersion[abi:cxx11]()'
4...
which is defined in the clientversion.cpp
:
0--- a/src/Makefile.am
1+++ b/src/Makefile.am
2@@ -972,6 +972,7 @@ lib_LTLIBRARIES += $(LIBBITCOINCONSENSUS)
3
4 include_HEADERS = script/bitcoinconsensus.h
5 libbitcoinconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_base_la_SOURCES) $(libbitcoin_consensus_a_SOURCES)
6+libbitcoinconsensus_la_SOURCES += clientversion.cpp util/check.cpp
7
8 libbitcoinconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
9 libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1)
This time a linker error is:
0$ make
1...
2 CXXLD libbitcoinconsensus.la
3/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]'
4...
which is supposed to be solved by this PR.
See #26504.
The last time those functions were moved in #24409.