2

I want to write in Makefile like this

foo: foo.c
        $(CC) -o foo -Wall foo.c

but I'm not sure if all cc implementations support -Wall.

pynexj
  • 19,215
  • 5
  • 38
  • 56
  • 1
    typically your makefile would have sections for each compiler you want to support where you'd define, say, `WARNINGS=-Wall` for gcc, `WARNINGS=/bla` for MSVC, and then the build command would be `$(CC) -o foo $(WARNINGS) foo.c` – M.M May 22 '17 at 10:28

2 Answers2

4

No, there is no standard regarding the command-line interface of C compilers.

The Microsoft compiler (in Windows) for instance does not accept options starting with - at all, since that's not the syntax typically used with Windows programs.

unwind
  • 391,730
  • 64
  • 469
  • 606
3

No, the closest thing you can do to use only portable options is to restrict yourself to the POSIX C89 and C99 options. -Wall is not one of them. See the Opengroup's Unix Specification for c99 for options which are. And that only gives answers for unixy systems, not Microsoft.

-Wall was (AFAIK) introduced by GNU gcc and inherited by clang to be compatible with GNU gcc.

If you are not afraid to research other build tools, there are some that support multi-OS or multi-toolchain builds out of the box. I believe scons and cmake can do this.

Jens
  • 69,818
  • 15
  • 125
  • 179