2

I use a library in my project which uses ZLIB library for compression. On the other hand I use CryptoPP library in my project. The consequence is that when compiling compiler makes a mistake and loads the zlib.h of CryptoPP instead of ZLIB.

Here is the compiler error:

/usr/local/include/crow/compression.h:25:13: error: ‘z_stream’ was not declared in this scope
   25 |             z_stream stream{};
      |             ^~~~
/usr/local/include/crow/compression.h:27:19: error: ‘::deflateInit2’ has not been declared
   27 |             if (::deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, algo, 8, Z_DEFAULT_STRATEGY) == Z_OK)
      |                   ^~~~~~
/usr/local/include/crow/compression.h:27:33: error: ‘stream’ was not declared in this scope; did you mean ‘std::io_errc::stream’?
   27 |             if (::deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, algo, 8, Z_DEFAULT_STRATEGY) == Z_OK)
      |                                 ^~~~
      |                                 std::io_errc:stream
/usr/local/include/crow/compression.h:27:41: error: ‘Z_DEFAULT_COMPRESSION’ was not declared in this scope; did you mean ‘CROW_ENABLE_COMPRESSION’?
   27 |             if (::deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, algo, 8, Z_DEFAULT_STRATEGY) == Z_OK)
      |                                         ^~~~~~~~~
      |                                         CROW_ENABLE_COMPRESSION
/usr/local/include/crow/compression.h:27:64: error: ‘Z_DEFLATED’ was not declared in this scope; did you mean ‘DEFLATE’?
   27 |             if (::deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, algo, 8, Z_DEFAULT_STRATEGY) == Z_OK)
      |                                                                ^~~~
      |                                                                DEFLATE
[ 78%] Building CXX object _deps/cryptopp-build/CMakeFiles/cryptest.dir/validat2.cpp.o
/usr/local/include/crow/compression.h:27:85: error: ‘Z_DEFAULT_STRATEGY’ was not declared in this scope
   27 |             if (::deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, algo, 8, Z_DEFAULT_STRATEGY) == Z_OK)
      |                                                                                     ^~~~~~~~
/usr/local/include/crow/compression.h:27:108: error: ‘Z_OK’ was not declared in this scope; did you mean ‘R_OK’?
   27 |             if (::deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, algo, 8, Z_DEFAULT_STRATEGY) == Z_OK)
      |                                                                                                            ^~
      |                                                                                                            R_OK
/usr/local/include/crow/compression.h:33:45: error: ‘Bytef’ does not name a type
   33 |                 stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(str.c_str()));
      |                                             ^~~
/usr/local/include/crow/compression.h:33:50: error: expected ‘>’ before ‘*’ token
   33 |                 stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(str.c_str()));
      |                                                  ^
/usr/local/include/crow/compression.h:33:50: error: expected ‘(’ before ‘*’ token
   33 |                 stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(str.c_str()));
      |                                                  ^
      |                                                  (
/usr/local/include/crow/compression.h:33:51: error: expected primary-expression before ‘>’ token
   33 |                 stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(str.c_str()));
      |                                                   ^
/usr/local/include/crow/compression.h:33:76: error: expected ‘>’ before ‘Bytef’
   33 |                 stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(str.c_str()));
      |                                                                            ^~~
/usr/local/include/crow/compression.h:33:76: error: expected ‘(’ before ‘Bytef’
   33 |                 stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(str.c_str()));
      |                                                                            ^~~
      |                                                                            (
/usr/local/include/crow/compression.h:33:76: error: ‘Bytef’ was not declared in this scope
   33 |                 stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(str.c_str()));
      |                                                                            ^~~
/usr/local/include/crow/compression.h:33:82: error: expected primary-expression before ‘>’ token
   33 |                 stream.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(str.c_str()));
      |              

It's just a part of errors. The rest is like above.

ZLIB, CryptoPP and the third party library are all installed on my ubuntu linux. The compiler is gcc 11.1.0.

What's your idea about this problem? How to address this issue?

navidcity
  • 31
  • 5
  • huh, why does this cryptopp library ship a zlib.h? It should almost certainly use the system's zlib.h. – Marcus Müller Jan 11 '22 at 15:45
  • 2
    You probably wanted to install all 3 libraries using the package management from your OS: [https://packages.ubuntu.com/search?keywords=crypto%2B%2B](https://packages.ubuntu.com/search?keywords=crypto%2B%2B) and [https://packages.ubuntu.com/search?suite=default&section=all&arch=any&keywords=zlib&searchon=names](https://packages.ubuntu.com/search?suite=default&section=all&arch=any&keywords=zlib&searchon=names) – drescherjm Jan 11 '22 at 15:46
  • 1
    Separate sources that call on zlib an CryptoPP, and for each source set different appropriate include paths. Do not add include paths for both zlib and CryptoPP on some "global" or "project" level. – Dialecticus Jan 11 '22 at 15:49
  • 1
    @MarcusMüller It just happens to contain a header file named `zlib.h`. It is not the `zlib.h` from the zlib library. I think the issue here is that the asker adds the CryptoPP path containing that file directly to the include path. – user17732522 Jan 11 '22 at 16:04
  • Please show a [mre] (including the compiler invocation and the directory layout / location of the header files). – user17732522 Jan 11 '22 at 16:05
  • That crypto++ seems to keep vast majority of its files flat in root directory of repo. No surprise that it is tricky to include something from such thing. – Öö Tiib Jan 11 '22 at 16:13
  • 1
    @ÖöTiib that's just the repository though, generally you'd build and install the library to a `cryptopp` subdirectory then do `#include ` – Alan Birtles Jan 11 '22 at 16:14
  • Exacty what Alan says here: I'm very confused why cryptopp would *ship* a zlib.h; this all sounds like someone is directly trying to with the source tree instead of properly first building and installing cryptopp and then using the appropriate includes. And as drescherjm says, the easiest way to install it is not bulding it yourself, but using your distro packages – Marcus Müller Jan 11 '22 at 16:53

0 Answers0