From 7c1fff3495376d135d78eaee8d86df86c6bfe9e2 Mon Sep 17 00:00:00 2001 From: Lance Fredrickson Date: Wed, 20 Oct 2021 05:26:25 -0600 Subject: [PATCH] builder: pass `-std=gnu99` to the C backend under linux (#12236) --- cmd/v/help/build-c.txt | 2 +- vlib/v/builder/cc.v | 6 +++++- vlib/v/pref/pref.v | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/v/help/build-c.txt b/cmd/v/help/build-c.txt index f4f0f14209..214e9da20c 100644 --- a/cmd/v/help/build-c.txt +++ b/cmd/v/help/build-c.txt @@ -243,7 +243,7 @@ see also `v help build`. compiler, on the command line, without writing an .rsp file first. -no-std - By default, V passes -std=c99 to the C backend, but some compilers do + By default, V passes -std=gnu99(linux)/-std=c99 to the C backend, but some compilers do not support that, even though they may be able to compile the produced code, or have other options that can be tuned to allow it. Passing -no-std will remove that flag, and you can then use -cflags '' diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 6e7dfc2f83..8fb68ce595 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -162,7 +162,11 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { // arguments for the C compiler ccoptions.args = [v.pref.cflags] if !v.pref.no_std { - ccoptions.args << '-std=c99 -D_DEFAULT_SOURCE' + if v.pref.os == .linux { + ccoptions.args << '-std=gnu99 -D_DEFAULT_SOURCE' + } else { + ccoptions.args << '-std=c99 -D_DEFAULT_SOURCE' + } } ccoptions.wargs = [ '-Wall', diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index ebf68cbc0b..6125b7f40b 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -176,7 +176,7 @@ pub mut: fatal_errors bool // unconditionally exit after the first error with exit(1) reuse_tmpc bool // do not use random names for .tmp.c and .tmp.c.rsp files, and do not remove them no_rsp bool // when true, pass C backend options directly on the CLI (do not use `.rsp` files for them, some older C compilers do not support them) - no_std bool // when true, do not pass -std=c99 to the C backend + no_std bool // when true, do not pass -std=gnu99(linux)/-std=c99 to the C backend use_color ColorOutput // whether the warnings/errors should use ANSI color escapes. no_parallel bool is_vweb bool // skip _ var warning in templates