cxong / tinydir

Lightweight, portable and easy to integrate C directory and file reader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work with MinGW-w64

eXpl0it3r opened this issue · comments

It looks like readdir_r is not supported by MinGW-w64 distributions. When I try to build the samples on my MinGW Builds 5.3.0 compiler, I get the following errors.

In file included from tinydir\samples\file_open_sample.c:2:0:
tinydir/tinydir.h: In function 'tinydir_open':
tinydir/tinydir.h:194:10: error: implicit declaration of function 'readdir_r' [-Werror=implicit-function-declaration]
  error = readdir_r(dir->_d, dir->_ep, &dir->_e);
          ^
tinydir/tinydir.h: In function '_tinydir_dirent_buf_size':
tinydir/tinydir.h:629:13: error: #error "buffer size for readdir_r cannot be determined"
 #           error "buffer size for readdir_r cannot be determined"
             ^

Is there an alternative?

commented

Some options, from easiest to hardest:

HTH

Thanks for the quick answers, guess I'll go with option one for now.

commented

No problem, thanks for raising the issue 👍 While I have your attention, I've made a quick fix that falls back to readdir for mingw; I've tested on my installation but I'm not sure if it's mingw-w64 - not too familiar with this environment. Could you please try this one out?

Note that readdir may not be threadsafe, so make sure that your program only ever uses one tinydir_dir at a time.

That's a fast turnaround. Unfortunately the tests fail to compile with the follow error:

tinydir/tinydir.h:290:6: error: inlining failed in call to 'tinydir_close': call is unlikely and code size would grow [-Werror=inline]
 void tinydir_close(tinydir_dir *dir)
      ^
tinydir/tinydir.h:180:2: error: called from here [-Werror=inline]
  tinydir_close(dir);
  ^
commented

Please try again; however I've discovered that the readdir_r implementation uses a lot of semi-standard functions that may not be available depending on compiler flags; e.g. it doesn't seem to work if -std=c99 is set. If it doesn't work, could you please show your compiler flags?

It's still going the #else branch and trying to force inlining with __inline__. Why can't you just use the inline keyword by default? Or is that not standard C?

Here's the command line CMake generates:

bin\gcc.exe   @CMakeFiles/file_open_sample.dir/includes_C.rsp -O3 -DNDEBUG   -fsigned-char -Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Winline -Werror -o CMakeFiles\file_open_sample.dir\file_open_sample.c.obj   -c tinydir\samples\file_open_sample.c
tinydir\samples\file_open_sample.c:2:0:
tinydir/tinydir.h: In function 'main':
tinydir/tinydir.h:292:6: error: inlining failed in call to 'tinydir_close': call is unlikely and code size would grow [-Werror=inline]
 void tinydir_close(tinydir_dir *dir)
      ^
commented

inline is standard C but only from C99 onward. I'll see if I can fix up that macro. What version of GCC are you using? I'm surprised that the macro doesn't work, since GCC should have STDC_VERSION.

I see. I'm using GCC 5.3.0 from MinGW Builds which uses MinGW-w64.

commented

Unfortunately I still can't reproduce the inline error. Here's what I tried:

  • Download and install MinGW-w64 for Windows, using mingw-w64-install.exe from https://sourceforge.net/projects/mingw-w64/

  • Install with GCC 5.3.0 / i686 / posix threads / dwarf exceptions

  • Under tinydir/samples, run cmake -G"MinGW Makefiles" . && mingw32-make; here's some output from the console:

    -- The C compiler identification is GNU 5.3.0
    -- Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-5.3.0-posix-dwarf-rt_v4-rev0/mingw32/bin/gcc.exe
    -- Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-5.3.0-posix-dwarf-rt_v4-rev0/mingw32/bin/gcc.exe -- works
    

So maybe I'm still using a different environment. You said you use MinGW Builds - how did you manage to get GCC 5.3.0; according to http://mingw-w64.org/doku.php/download the latest is 4.9.2?

Oh my bad, for some reason I didn't pull down the macro changes (maybe I was in the wrong directory?), anyways I just updated and it seems to work fine now. 👍

I've installed the same compiler, as you then. The MinGW-w64 project's website seems to not get updated very often.

Thanks for the quick fix and sorry again that you had to spend your time checking the compiler yourself.

commented

No problem, thanks for following up 😎