decitrig
decitrig

Reputation: 788

How to compile with --pedantic-errors on OS X?

Here's a simple C file:

#include <stdio.h>
#include <stdlib.h>

int
main() {
    printf("hi there!\n");
    return 0;
}

Compiling with gcc -ansi -pedantic -pedantic-errors gives this:

In file included from /usr/include/i386/_structs.h:38,
             from /usr/include/machine/_structs.h:31,
             from /usr/include/sys/_structs.h:57,
             from /usr/include/sys/signal.h:154,
             from /usr/include/sys/wait.h:116,
             from /usr/include/stdlib.h:65,
             from test.c:2:
/usr/include/mach/i386/_structs.h:91: error: type of bit-field ‘__invalid’ is a GCC extension

With lots more errors about GCC extensions. I know that I could just remove the -pedantic-errors switch and recompile, but for one reason and another, that isn't in the cards. Is there a way to get past this error; perhaps downloading & installing another C library? I'm working locally on code that needs to compile on a remote machine, so I can't set up the Makefile to point at a special library location, unfortunately.

Upvotes: 2

Views: 990

Answers (1)

Clifford
Clifford

Reputation: 93476

You could possibly modify /usr/include/mach/i386/_structs.h:91 to use the __extension__ keyword. Although you'd have to wonder why this is not already the case.

Another file level solution is to add a #pragma GCC system_header directive to the top of _structs.h.

To fix it at the build level, add -isystem /usr/include/mach/i386/ to the compiler options. All headers in that folder will then be included as if they were system headers (which should be the case already but apparently is not).

Upvotes: 1

Related Questions