drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.04k stars 1.06k forks source link

error on compiling source code #2030

Closed ProTankerAlfa closed 1 month ago

ProTankerAlfa commented 1 month ago

Many errors on compiling source code of drogon in HttpResponseImpl.cc file:

.../drogon/lib/src/HttpRequestImpl.cc: In member function ‘drogon::StreamDecompressStatus drogon::HttpRequestImpl::decompressBodyGzip()’:
.../home/protankeralfa/AlexandriaCMS/drogon/lib/src/HttpRequestImpl.cc:898:5: error: ‘z_stream’ was not declared in this scope
  898 |     z_stream strm = {nullptr,
      |     ^~~~~~~~
.../drogon/lib/src/HttpRequestImpl.cc:912:5: error: ‘strm’ was not declared in this scope; did you mean ‘tm’?
  912 |     strm.next_in = (Bytef *)compressed.data();
      |     ^~~~
      |     tm
.../drogon/lib/src/HttpRequestImpl.cc:912:21: error: ‘Bytef’ was not declared in this scope
  912 |     strm.next_in = (Bytef *)compressed.data();
      |                     ^~~~~
.../drogon/lib/src/HttpRequestImpl.cc:912:28: error: expected primary-expression before ‘)’ token
  912 |     strm.next_in = (Bytef *)compressed.data();
      |                            ^
.../drogon/lib/src/HttpRequestImpl.cc:913:33: error: ‘uInt’ does not name a type; did you mean ‘uint’?
  913 |     strm.avail_in = static_cast<uInt>(compressed.size());
      |                                 ^~~~
      |                                 uint
.../drogon/lib/src/HttpRequestImpl.cc:915:19: error: ‘Z_NULL’ was not declared in this scope; did you mean ‘NULL’?
  915 |     strm.zalloc = Z_NULL;
      |                   ^~~~~~
      |                   NULL
.../drogon/lib/src/HttpRequestImpl.cc:924:29: error: expected primary-expression before ‘)’ token
  924 |     strm.next_out = (Bytef *)decompressed.data();
      |                             ^
.../drogon/lib/src/HttpRequestImpl.cc:925:34: error: ‘uInt’ does not name a type; did you mean ‘uint’?
  925 |     strm.avail_out = static_cast<uInt>(decompressed.size());
      |                                  ^~~~
      |                                  uint
.../drogon/lib/src/HttpRequestImpl.cc:927:9: error: ‘inflateInit2’ was not declared in this scope
  927 |     if (inflateInit2(&strm, (15 + 32)) != Z_OK)
      |         ^~~~~~~~~~~~
.../drogon/lib/src/HttpRequestImpl.cc:927:43: error: ‘Z_OK’ was not declared in this scope; did you mean ‘F_OK’?
  927 |     if (inflateInit2(&strm, (15 + 32)) != Z_OK)
      |                                           ^~~~
      |                                           F_OK
.../drogon/lib/src/HttpRequestImpl.cc:936:47: error: ‘Z_SYNC_FLUSH’ was not declared in this scope
  936 |         int decompressStatus = inflate(&strm, Z_SYNC_FLUSH);
      |                                               ^~~~~~~~~~~~
.../drogon/lib/src/HttpRequestImpl.cc:936:32: error: ‘inflate’ was not declared in this scope
  936 |         int decompressStatus = inflate(&strm, Z_SYNC_FLUSH);
      |                                ^~~~~~~
.../drogon/lib/src/HttpRequestImpl.cc:947:33: error: ‘Z_STREAM_END’ was not declared in this scope
  947 |         if (decompressStatus == Z_STREAM_END)
      |                                 ^~~~~~~~~~~~
.../drogon/lib/src/HttpRequestImpl.cc:952:38: error: ‘Z_OK’ was not declared in this scope; did you mean ‘F_OK’?
  952 |         else if (decompressStatus != Z_OK)
      |                                      ^~~~
      |                                      F_OK
.../drogon/lib/src/HttpRequestImpl.cc:964:37: error: expected primary-expression before ‘)’ token
  964 |             strm.next_out = (Bytef *)decompressed.data();
      |                                     ^
.../drogon/lib/src/HttpRequestImpl.cc:965:42: error: ‘uInt’ does not name a type; did you mean ‘uint’?
  965 |             strm.avail_out = static_cast<uInt>(decompressed.size());
      |                                          ^~~~
      |                                          uint
.../drogon/lib/src/HttpRequestImpl.cc:968:9: error: ‘inflateEnd’ was not declared in this scope
  968 |     if (inflateEnd(&strm) != Z_OK)
      |         ^~~~~~~~~~
.../drogon/lib/src/HttpRequestImpl.cc:968:30: error: ‘Z_OK’ was not declared in this scope; did you mean ‘F_OK’?
  968 |     if (inflateEnd(&strm) != Z_OK)
      |                              ^~~~
      |                              F_OK

g++ (WSL 2.0 Debian) || c++20

ProTankerAlfa commented 1 month ago

it seems that it is important to another zlib.h on my system, I'm checking

ProTankerAlfa commented 1 month ago

It was getting zlib.h from the cryptopp lib, I changed the include of HttpRequestImpl.cc and Utilities.cc to #include "../zlib.h" and it worked

hwc0919 commented 1 month ago

The better way is to set ZLIB_ROOT when running cmake.

https://cmake.org/cmake/help/latest/module/FindZLIB.html#hints