0001-Fix-building-when-only-writer-support-is-enabled.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. From aef33b66df0ad6f085dc55b50d7847e0b8a2ccd8 Mon Sep 17 00:00:00 2001
  2. From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
  3. Date: Wed, 17 Jul 2024 14:53:35 +0200
  4. Subject: [PATCH] Fix building when only writer support is enabled
  5. The compilation of the following code, which links the zxing-cpp library
  6. built with only the writer (encoder) support, raises the following
  7. linking errors:
  8. using namespace ZXing;
  9. int main(void)
  10. {
  11. std::string str = "01";
  12. BitHacks::NumberOfLeadingZeros(0);
  13. auto writer = MultiFormatWriter(BarcodeFormat::Code128);
  14. writer.setEncoding(CharacterSet::UTF8);
  15. writer.setMargin(0);
  16. auto matrix = writer.encode(str, 0, 0 /*scaledImageWidth, pixelHeight*/);
  17. return EXIT_SUCCESS;
  18. }
  19. arm-buildroot-linux-uclibcgnueabihf/bin/ld:host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/lib/libZXing.so:
  20. undefined reference to `ZXing::TextDecoder::GuessEncoding(unsigned char const*, unsigned int, ZXing::CharacterSet)'
  21. arm-buildroot-linux-uclibcgnueabihf/bin/ld: host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/lib/libZXing.so:
  22. undefined reference to `ZXing::HRIFromGS1[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >)'
  23. arm-buildroot-linux-uclibcgnueabihf/bin/ld: host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/lib/libZXing.so:
  24. undefined reference to `ZXing::TextDecoder::Append(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned char const*, unsigned int, ZXing::CharacterSet, bool)'
  25. arm-buildroot-linux-uclibcgnueabihf/bin/ld: host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/lib/libZXing.so:
  26. undefined reference to `ZXing::HRIFromISO15434[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >)'
  27. collect2: error: ld returned 1 exit status
  28. The patch fixes these errors.
  29. Co-Developed-by: Francesco Nicoletta Puzzillo <francesco.nicolettap@amarula>
  30. Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
  31. Upstream: backport from upstream https://github.com/zxing-cpp/zxing-cpp/pull/811
  32. ---
  33. core/src/Content.cpp | 4 ++++
  34. core/src/Content.h | 6 ++++++
  35. core/src/DecoderResult.h | 2 ++
  36. core/src/GTIN.cpp | 2 ++
  37. core/src/GTIN.h | 2 ++
  38. 5 files changed, 16 insertions(+)
  39. diff --git a/core/src/Content.cpp b/core/src/Content.cpp
  40. index 4d3c44657cf9..569d4e35614a 100644
  41. --- a/core/src/Content.cpp
  42. +++ b/core/src/Content.cpp
  43. @@ -93,6 +93,7 @@ bool Content::canProcess() const
  44. return std::all_of(encodings.begin(), encodings.end(), [](Encoding e) { return CanProcess(e.eci); });
  45. }
  46. +#ifdef ZXING_READERS
  47. std::string Content::render(bool withECI) const
  48. {
  49. if (empty() || !canProcess())
  50. @@ -165,6 +166,7 @@ std::wstring Content::utfW() const
  51. {
  52. return FromUtf8(render(false));
  53. }
  54. +#endif // ZXING_READERS
  55. ByteArray Content::bytesECI() const
  56. {
  57. @@ -188,6 +190,7 @@ ByteArray Content::bytesECI() const
  58. return ByteArray(res);
  59. }
  60. +#ifdef ZXING_READERS
  61. CharacterSet Content::guessEncoding() const
  62. {
  63. // assemble all blocks with unknown encoding
  64. @@ -236,5 +239,6 @@ ContentType Content::type() const
  65. return ContentType::Mixed;
  66. }
  67. +#endif // ZXING_READERS
  68. } // namespace ZXing
  69. diff --git a/core/src/Content.h b/core/src/Content.h
  70. index 99e5a01e7140..aa77bda94d54 100644
  71. --- a/core/src/Content.h
  72. +++ b/core/src/Content.h
  73. @@ -38,7 +38,9 @@ class Content
  74. void ForEachECIBlock(FUNC f) const;
  75. void switchEncoding(ECI eci, bool isECI);
  76. +#ifdef ZXING_READERS
  77. std::string render(bool withECI) const;
  78. +#endif // ZXING_READERS
  79. public:
  80. struct Encoding
  81. @@ -75,13 +77,17 @@ public:
  82. bool empty() const { return bytes.empty(); }
  83. bool canProcess() const;
  84. +#ifdef ZXING_READERS
  85. std::string text(TextMode mode) const;
  86. std::wstring utfW() const; // utf16 or utf32 depending on the platform, i.e. on size_of(wchar_t)
  87. std::string utf8() const { return render(false); }
  88. +#endif // ZXING_READERS
  89. ByteArray bytesECI() const;
  90. +#ifdef ZXING_READERS
  91. CharacterSet guessEncoding() const;
  92. ContentType type() const;
  93. +#endif // ZXING_READERS
  94. };
  95. } // ZXing
  96. diff --git a/core/src/DecoderResult.h b/core/src/DecoderResult.h
  97. index 02b285084195..3117b03a923a 100644
  98. --- a/core/src/DecoderResult.h
  99. +++ b/core/src/DecoderResult.h
  100. @@ -50,7 +50,9 @@ public:
  101. Content&& content() && { return std::move(_content); }
  102. // to keep the unit tests happy for now:
  103. +#ifdef ZXING_READERS
  104. std::wstring text() const { return _content.utfW(); }
  105. +#endif // ZXING_READERS
  106. std::string symbologyIdentifier() const { return _content.symbology.toString(false); }
  107. // Simple macro to set up getter/setter methods that save lots of boilerplate.
  108. diff --git a/core/src/GTIN.cpp b/core/src/GTIN.cpp
  109. index 256855a03070..690901062301 100644
  110. --- a/core/src/GTIN.cpp
  111. +++ b/core/src/GTIN.cpp
  112. @@ -199,6 +199,7 @@ std::string LookupCountryIdentifier(const std::string& GTIN, const BarcodeFormat
  113. return it != std::end(COUNTRIES) && prefix >= it->first && prefix <= it->last ? it->id : std::string();
  114. }
  115. +#ifdef ZXING_READERS
  116. std::string EanAddOn(const Result& result)
  117. {
  118. if (!(BarcodeFormat::EAN13 | BarcodeFormat::UPCA | BarcodeFormat::UPCE | BarcodeFormat::EAN8)
  119. @@ -208,6 +209,7 @@ std::string EanAddOn(const Result& result)
  120. auto pos = txt.find(' ');
  121. return pos != std::string::npos ? std::string(txt.substr(pos + 1)) : std::string();
  122. }
  123. +#endif // ZXING_READERS
  124. std::string IssueNr(const std::string& ean2AddOn)
  125. {
  126. diff --git a/core/src/GTIN.h b/core/src/GTIN.h
  127. index d56b604e5f71..9af0b01200ce 100644
  128. --- a/core/src/GTIN.h
  129. +++ b/core/src/GTIN.h
  130. @@ -47,7 +47,9 @@ bool IsCheckDigitValid(const std::basic_string<T>& s)
  131. */
  132. std::string LookupCountryIdentifier(const std::string& GTIN, const BarcodeFormat format = BarcodeFormat::None);
  133. +#ifdef ZXING_READERS
  134. std::string EanAddOn(const Result& result);
  135. +#endif // ZXING_READERS
  136. std::string IssueNr(const std::string& ean2AddOn);
  137. std::string Price(const std::string& ean5AddOn);
  138. --
  139. 2.43.0