jivanpal / drat

Utility for performing data recovery and analysis of APFS partitions/containers.
GNU General Public License v3.0
163 stars 21 forks source link

error: "S_IFMT" redefined [-Werror] #40

Closed webstey closed 8 months ago

webstey commented 2 years ago

Attempting to build on ubuntuy 20.04, get errors from include/apfs/jconst.c about macros on lines 176-184 being redfined (previous definition /usr/include/fcntl.h).

gcc (Ubuntu 9.4.0-1ubuntu1-20.04.1) 9.4.0, Gnu Make 4.2.1, ldd (Ubuntu GLIBC 2.31-0ubuntu9.9) 2.31

I was able to make it build by commenting out the offending lines 176-184 from jconst.c and adding a #include of in include/drat/string/j.c , but I suspect this is a workaround as opposed to a fix (did not delve into it any further after it built).

Sample output from make:

OBJECTS +++ src/commands/recover.c +++ out/src/commands/recover.o
gcc -std=c99 -D _GNU_SOURCE -Werror -Wall -Wextra -Wno-incompatible-pointer-types -Wno-multichar -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -I./include -c "src/commands/recover.c" -o "out/src/commands/recover.o"
In file included from ./include/apfs/j.h:10,
                 from ./include/apfs/crypto.h:12,
                 from ./include/apfs/fs.h:10,
                 from src/commands/recover.c:13:
./include/apfs/jconst.h:176: error: "S_IFMT" redefined [-Werror]
  176 | #define S_IFMT      0170000
      | 
In file included from src/commands/recover.c:8:
/usr/include/fcntl.h:80: note: this is the location of the previous definition
   80 | # define S_IFMT  __S_IFMT
      | 
jivanpal commented 2 years ago

Thanks, I will try to reproduce.

nurgling commented 2 years ago

The same issue happens on Fedora 36. I could compile with the above workaround.

jivanpal commented 8 months ago

I think this is due to these fcntl macros being predefined in GNU's glibc, but not in Apple's/BSD's, so no such compilation error on most Mac setups. I've recently guarded the (re-)definitions with an #ifndef that should prevent this error on platforms that use GNU glibc or otherwise have the constants already defined. Please reply here or open a new issue if this persists.

nurgling commented 8 months ago

Thanks for the fix. Compilation works for me now.