sebastiandev / zipper

C++ wrapper around minizip compression library
MIT License
506 stars 123 forks source link

Cannot compile with mingw-w64 under msys2 #72

Closed GiuseppeCesarano closed 3 years ago

GiuseppeCesarano commented 3 years ago

When trying to compile with mingw-w64 under msys2 the error: "The opendir() API is provided by this compiler, so should not be built here" is raised.

GiuseppeCesarano commented 3 years ago

When i force off "USE_WINDOWS" the following errors are raised:

_deps/zipper-src/zipper/unzipper.cpp: In member function 'void zipper::Unzipper::Impl::changeFileDate(const string&, uLong, tm_unz)':
_deps/zipper-src/zipper/unzipper.cpp:196:9: error: 'HANDLE' was not declared in this scope
  196 |         HANDLE hFile;
      |         ^~~~~~
_deps/zipper-src/zipper/unzipper.cpp:197:9: error: 'FILETIME' was not declared in this scope; did you mean 'ETIME'?
  197 |         FILETIME ftm, ftLocal, ftCreate, ftLastAcc, ftLastWrite;
      |         ^~~~~~~~
      |         ETIME
_deps/zipper-src/zipper/unzipper.cpp:199:9: error: 'hFile' was not declared in this scope; did you mean 'gzFile'?
  199 |         hFile = CreateFileA(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
      |         ^~~~~
      |         gzFile
_deps/zipper-src/zipper/unzipper.cpp:199:47: error: 'GENERIC_READ' was not declared in this scope
  199 |         hFile = CreateFileA(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
      |                                               ^~~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:199:62: error: 'GENERIC_WRITE' was not declared in this scope
  199 |         hFile = CreateFileA(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
      |                                                              ^~~~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:199:86: error: 'OPEN_EXISTING' was not declared in this scope
  199 |         hFile = CreateFileA(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
      |                                                                                      ^~~~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:199:17: error: 'CreateFileA' was not declared in this scope
  199 |         hFile = CreateFileA(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
      |                 ^~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:200:22: error: 'INVALID_HANDLE_VALUE' was not declared in this scope
  200 |         if (hFile != INVALID_HANDLE_VALUE)
      |                      ^~~~~~~~~~~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:202:33: error: 'ftCreate' was not declared in this scope
  202 |             GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
      |                                 ^~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:202:44: error: 'ftLastAcc' was not declared in this scope
  202 |             GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
      |                                            ^~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:202:56: error: 'ftLastWrite' was not declared in this scope
  202 |             GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
      |                                                        ^~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:202:13: error: 'GetFileTime' was not declared in this scope
  202 |             GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
      |             ^~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:203:36: error: 'WORD' was not declared in this scope
  203 |             DosDateTimeToFileTime((WORD)(dosdate >> 16), (WORD)dosdate, &ftLocal);
      |                                    ^~~~
_deps/zipper-src/zipper/unzipper.cpp:203:64: error: expected ')' before 'dosdate'
  203 |             DosDateTimeToFileTime((WORD)(dosdate >> 16), (WORD)dosdate, &ftLocal);
      |                                  ~                             ^~~~~~~
      |                                                                )
_deps/zipper-src/zipper/unzipper.cpp:203:74: error: 'ftLocal' was not declared in this scope
  203 |             DosDateTimeToFileTime((WORD)(dosdate >> 16), (WORD)dosdate, &ftLocal);
      |                                                                          ^~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:203:13: error: 'DosDateTimeToFileTime' was not declared in this scope
  203 |             DosDateTimeToFileTime((WORD)(dosdate >> 16), (WORD)dosdate, &ftLocal);
      |             ^~~~~~~~~~~~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:204:48: error: 'ftm' was not declared in this scope; did you mean 'tm'?
  204 |             LocalFileTimeToFileTime(&ftLocal, &ftm);
      |                                                ^~~
      |                                                tm
_deps/zipper-src/zipper/unzipper.cpp:204:13: error: 'LocalFileTimeToFileTime' was not declared in this scope
  204 |             LocalFileTimeToFileTime(&ftLocal, &ftm);
^~~~~~~~~~~~~~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:205:13: error: 'SetFileTime' was not declared in this scope
  205 |             SetFileTime(hFile, &ftm, &ftLastAcc, &ftm);
      |             ^~~~~~~~~~~
_deps/zipper-src/zipper/unzipper.cpp:206:13: error: 'CloseHandle' was not declared in this scope
  206 |             CloseHandle(hFile);
      |             ^~~~~~~~~~~
[160/233] Building CXX object _deps/cpr-build/cpr/CMakeFiles/cpr.dir/session.cpp.obj
[161/233] Building CXX object _deps/zipper-build/CMakeFiles/Zipper-static.dir/zipper/CDirEntry.cpp.obj
FAILED: _deps/zipper-build/CMakeFiles/Zipper-static.dir/zipper/CDirEntry.cpp.obj 
D:\a\_temp\msys\msys64\mingw64\bin\c++.exe  -DLINUX -DUSE_ZLIB -I_deps/zipper-src/minizip -I_deps/zipper-src/zipper -I_deps/zipper-src -I_deps/zipper-build -fno-strict-aliasing -fPIC -O3 -DNDEBUG   -std=gnu++11 -MD -MT _deps/zipper-build/CMakeFiles/Zipper-static.dir/zipper/CDirEntry.cpp.obj -MF _deps\zipper-build\CMakeFiles\Zipper-static.dir\zipper\CDirEntry.cpp.obj.d -o _deps/zipper-build/CMakeFiles/Zipper-static.dir/zipper/CDirEntry.cpp.obj -c _deps/zipper-src/zipper/CDirEntry.cpp
_deps/zipper-src/zipper/CDirEntry.cpp: In static member function 'static bool zipper::CDirEntry::createDir(const string&, const string&)':
_deps/zipper-src/zipper/CDirEntry.cpp:229:59: error: too many arguments to function 'int mkdir(const char*)'
  229 |     return (mkdir(Dir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) == 0);
      |                                                           ^
In file included from D:/a/_temp/msys/msys64/mingw64/x86_64-w64-mingw32/include/fcntl.h:8,
                 from _deps/zipper-src/zipper/defs.h:10,
                 from _deps/zipper-src/zipper/CDirEntry.cpp:17:
D:/a/_temp/msys/msys64/mingw64/x86_64-w64-mingw32/include/io.h:282:15: note: declared here
  282 |   int __cdecl mkdir (const char *) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
      |               ^~~~~

I'm using msys2 in github actions, I'm following this guide

Lecrapouille commented 3 years ago

@GiuseppeCesarano Are you able to pass the cmake step Looking for gzopen in LIBZ_LIBRARY-NOTFOUND ? I would like to fix my appveyor file but I do not know to do that ? How did you make ?

GiuseppeCesarano commented 3 years ago

This is what my github action looks like:

name: Release

on: [push]

jobs:
  Release:
    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 {0}
    steps:
      - uses: actions/checkout@v2
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MINGW64
          update: true
          install: git mingw-w64-x86_64-toolchain
      - name: Install dependencies
        run: |
          pacman -Syu
          pacman -S --noconfirm mingw-w64-x86_64-gcc mingw-w64-x86_64-gtkmm3 pkg-config mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-zlib
      - name: Build
        run: |
          export PATH=$PATH:/mingw64/bin
          cmake -B build -GNinja -DCMAKE_BUILD_TYPE=Release -DTESTS=ON .
          cd build && cmake --build .
// Continues with some irrelevant stuff

I'm compiling a gtkmm3 application and it has this project as dependency. I didn't take a look to your appveyor but let me trow a wild guess, could it be the mingw-w64-x86_64-zlib dependency to do the trick?

GiuseppeCesarano commented 3 years ago

I think i got why it isn't working. Your cmake is using MSVC 19.0.24241.7 as default compiler, and maybe it's also using the Visual Studio build system, you should force it to use the mingw patched compiler and also a mingw patched build system (I would suggest mingw-w64-x86_64-ninja)

Lecrapouille commented 3 years ago

@GiuseppeCesarano Thanks I'll check in coming days :) No biggie for gtkmm3 since I also do C++ project with GTK+ :) For zlib I have here https://github.com/sebastiandev/zipper/blob/master/.integration/appveyor-install-window.sh#L19 called by https://github.com/sebastiandev/zipper/blob/master/appveyor.yml#L32

GiuseppeCesarano commented 3 years ago

Closing this issue since it's fixed with #73. Also the appveyor is fixed with #76!