ITADN

mingw32-make ignores override CFLAGS and forces -std=c17 (WinLibs GCC 15.2.0)

#282OpenJaakkoJSeppala 创建于 2025-11-04
J
JaakkoJSeppalacommented
**Environment:** - OS: Windows 10/11 - Toolchain: WinLibs MinGW-W64 (GCC 15.2.0 UCRT-posix) - Build tool: mingw32-make.exe shipped with WinLibs - Shell: PowerShell 7 (also reproducible in cmd.exe) - Sample Makefile: (see below) - Sample code uses standard library function `sqrt()` among others. **Description:** When using mingw32-make with a Makefile containing an override for CFLAGS, for example: override CFLAGS = -std=gnu17 -O2 -Wall -I. -D_USE_MATH_DEFINES the actual compile commands produced during build still include: gcc -std=c17 -O2 -Wall -I. -c main.c -o build/main.o gcc -std=c17 -O2 -Wall -I. -c sph.c -o build/sph.o Thus the `-std=gnu17` setting is ignored and replaced with `-std=c17`. This causes issues such as implicit declaration warnings/errors for `sqrt()` and other standard library functions. **Steps to reproduce:** 1. Download and install WinLibs MinGW-W64 (GCC 15.2.0 UCRT-posix) 2. Create a Makefile with content like: override CFLAGS = -std=gnu17 -O2 -Wall -I. -D_USE_MATH_DEFINES CC = gcc LDFLAGS = -lm SRC = main.c sph.c OBJ = $(SRC:%.c=build/%.o) TARGET = bin/sphdem.exe build/%.o: %.c $(CC) $(CFLAGS) -c $< -o $@ 3. In a `.c` file (e.g., `vector.c` or `sph.c`), call `sqrt()` from `<math.h>`, e.g.: ```c #include <math.h> double vec_len(Vec3 a) { return sqrt(a.x*a.x + a.y*a.y + a.z*a.z); } 4. run mingw32-make -f Makefile clean mingw32-make -f Makefile 5. Observe output showing gcc -std=c17 … and build failure or warnings for sqrt(). 6. Expected behavior: The compile command should respect the Makefile’s CFLAGS override and use -std=gnu17 (or whatever standard is specified) instead of defaulting to -std=c17. Actual behavior: mingw32-make ignores the override and uses -std=c17 by default, causing warning/error. Workarounds: Manually specify the standard in the rule, e.g.: $(CC) -std=gnu17 -O2 -Wall -I. -D_USE_MATH_DEFINES -c $< -o $@ Use a different make implementation (e.g., from MSYS2 or GNU Make) where the override works. Avoid relying on override CFLAGS = …. Additional information: This issue appears specific to the WinLibs distribution of mingw32-make or its default rule behavior. Other environments might not exhibit this. 7.
0 条评论