Related to #33550 (comment)
Extends 7703884 to guard environ declaration on all Windows builds, not just MSVC. llvm-mingw also defines environ as a macro that expands to a dllimport function, causing the same inconsistent linkage warning.
Use WIN32
instead of _MSC_VER
to match the platform-specific guards already used throughout the file.
The warning occurs with llvm-mingw
(both UCRT
and MSVCRT
variants as tested by Hebasto), but not with the mingw-w64
toolchain currently used in CI (as mentioned by fanquake).
The error was reproduced by adding a temporary nightly build pointing to https://github.com/l0rinc/bitcoin/pull/45. On master
the failure can be seen in https://github.com/l0rinc/bitcoin-core-nightly/pull/2
before: https://github.com/l0rinc/bitcoin-core-nightly/actions/runs/18327936488/job/52196728885?pr=2
0/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/src/randomenv.cpp:61:15: warning: '__p__environ' redeclared without 'dllimport' attribute: previous 'dllimport' ignored [-Winconsistent-dllimport]
1 61 | extern char** environ; // NOLINT(readability-redundant-declaration): Necessary on some platforms
2 | ^
3/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/stdlib.h:656:17: note: expanded from macro 'environ'
4 656 | #define environ _environ
5 | ^
6/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/stdlib.h:225:21: note: expanded from macro '_environ'
7 225 | #define _environ (* __p__environ())
8 | ^
9/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/stdlib.h:221:27: note: previous declaration is here
10 221 | _CRTIMP char ***__cdecl __p__environ(void);
11 | ^
12/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/stdlib.h:221:3: note: previous attribute is here
13 221 | _CRTIMP char ***__cdecl __p__environ(void);
14 | ^
15/home/runner/work/bitcoin-core-nightly/bitcoin-core-nightly/llvm_mingw_toolchain/aarch64-w64-mingw32/include/_mingw.h:52:40: note: expanded from macro '_CRTIMP'
16 52 | # define _CRTIMP __attribute__ ((__dllimport__))
17 | ^
181 warning generated.
after: https://github.com/l0rinc/bitcoin-core-nightly/actions/runs/18329616268/job/52201940831?pr=4
0[ 28%] Building CXX object src/util/CMakeFiles/bitcoin_util.dir/__/randomenv.cpp.obj
Note that there are some other remaining warnings in the logs that will be fixed in separate PRs