Skip to content

Fix several Windows build warnings#59634

Merged
fingolfin merged 1 commit intomasterfrom
ct/win-fix-warnings
Sep 24, 2025
Merged

Fix several Windows build warnings#59634
fingolfin merged 1 commit intomasterfrom
ct/win-fix-warnings

Conversation

@topolarity
Copy link
Copy Markdown
Member

Should fix:

  • [-Wstrict-prototypes]
  • [-Wattributes]
  • [-Wc++-compat]
  • [-Wunused-but-set-variable]
  • [-Wdiscarded-qualifiers]
  • [-Wundef]

This leaves:

  • [-Warray-bounds]
  • [-Winfinite-recursion]

see JuliaCI/julia-buildkite#484

Comment thread src/sys.c Outdated
#else
#if !defined(_OS_WINDOWS_) || defined(_COMPILER_GCC_)
extern char **environ;
#if (!defined(_OS_WINDOWS_) || defined(_COMPILER_GCC_)) && !defined(environ)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this check? The C standard states that environ is required to be defined by the user (thus must not be a macro)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm attempting to fix:

  | C:/workdir/src/sys.c:500:1: warning: function declaration isn't a prototype [-Wstrict-prototypes]
  | 500 \| extern char **environ;
  | \| ^~~~~~
  | In file included from C:/workdir/src/sys.c:8:
  | C:/workdir/src/sys.c:500:15: warning: '__p__environ' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
  | 500 \| extern char **environ;
  | \|               ^~~~~~~

but this doesn't reproduce for me locally (MinGW 11.5.0) so I don't know where this definition is coming from yet.

Presumably it's something like https://github.com/mirror/mingw-w64/blob/93f3505a758fe70e56678f00e753af3bc4f640bb/mingw-w64-headers/crt/stdlib.h#L595 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduces with:

// #define _POSIX_ // if uncommented, everything works
#define _UCRT
#include <stdlib.h>
extern char **environ;
$ x86_64-w64-mingw32-gcc -Wstrict-prototypes -c test.c
test.c:4:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
    4 | extern char **environ;
      | ^~~~~~
In file included from test.c:3:
test.c:4:15: warning: ‘__p__environ’ redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
    4 | extern char **environ;
      |

maybe the right guard is defined( _POSIX_C_SOURCE )

Comment thread Make.inc
JLDFLAGS += -Wl,--large-address-aware
endif
JCPPFLAGS += -D_WIN32_WINNT=_WIN32_WINNT_WIN8
JCPPFLAGS += -D_WIN32_WINNT=0x0602 # (0x0602 = _WIN32_WINNT_WIN8)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the problem with _WIN32_WINNT_WIN8? It wasn't defined at some point? If so, maybe the offending file wasn't included a header file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's all over our old logs: https://buildkite.com/julialang/julia-master/builds/50748#019972b4-b648-4997-9624-70e22d7230dc/864-2038

I'm not sure why that happens, but until recently (cbea8cf) we always just used the hex code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure sdkddkver.h is included in the file which needed the macro?

Copy link
Copy Markdown
Member Author

@topolarity topolarity Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It reproduces for me with:

$ x86_64-w64-mingw32-g++ -D_WIN32_WINNT=_WIN32_WINNT_WIN8 -Wundef -c -x c++ - <<<"#include <mutex>"
<command-line>: warning: "_WIN32_WINNT_WIN8" is not defined, evaluates to 0 [-Wundef]

seems like a MinGW issue

Copy link
Copy Markdown
Member

@giordano giordano Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia> BinaryBuilderBase.runshell(Platform("x86_64", "windows"); preferred_gcc_version=v"10");
sandbox:${WORKSPACE} # echo "" | g++ -dM -E -std=c++17 -x c++ - | grep _WIN32_WINNT_WIN8
sandbox:${WORKSPACE} # echo "#include <mutex>" | g++ -dM -E -std=c++17 -x c++ - | grep _WIN32_WINNT_WIN8
sandbox:${WORKSPACE} # echo "#include <sdkddkver.h>" | g++ -dM -E -std=c++17 -x c++ - | grep _WIN32_WINNT_WIN8
#define _WIN32_WINNT_WIN8 0x0602

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I take away from that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sdkddkver.h is necessary for the macro to be defined, which is what I've been trying to say from https://github.com/JuliaLang/julia/pull/59634#discussion_r2372580441🙂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why should you have to include <sdkddkver.h> everywhere you use the C++ standard library?

Copy link
Copy Markdown
Member

@giordano giordano Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, that's because the macro is defined in the command line arguments passed everywhere.

BTW, nowadays Windows 10 is the minimum supported version.

@topolarity topolarity force-pushed the ct/win-fix-warnings branch 2 times, most recently from 20c5e73 to c725965 Compare September 23, 2025 20:38
Should fix:
  - `[-Wstrict-prototypes]`
  - `[-Wattributes]`
  - `[-Wc++-compat]`
  - `[-Wunused-but-set-variable]`
  - `[-Wdiscarded-qualifiers]`
  - `[-Wundef]`

This leaves:
  - `[-Warray-bounds]`
  - `[-Winfinite-recursion]`
@topolarity topolarity added the merge me PR is reviewed. Merge when all tests are passing label Sep 23, 2025
@fingolfin fingolfin merged commit 874c330 into master Sep 24, 2025
8 checks passed
@fingolfin fingolfin deleted the ct/win-fix-warnings branch September 24, 2025 09:54
@oscardssmith oscardssmith added building Build system, or building Julia or its dependencies system:windows Affects only Windows and removed merge me PR is reviewed. Merge when all tests are passing labels Sep 24, 2025
xal-0 pushed a commit to xal-0/julia that referenced this pull request Sep 30, 2025
Should fix:
  - `[-Wstrict-prototypes]`
  - `[-Wattributes]`
  - `[-Wc++-compat]`
  - `[-Wunused-but-set-variable]`
  - `[-Wdiscarded-qualifiers]`
  - `[-Wundef]`

This leaves:
  - `[-Warray-bounds]`
  - `[-Winfinite-recursion]`

see JuliaCI/julia-buildkite#484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

building Build system, or building Julia or its dependencies system:windows Affects only Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants