[
https://issues.apache.org/jira/browse/THRIFT-6249?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Sylwester Lachiewicz resolved THRIFT-6249.
------------------------------------------
Resolution: Duplicate
> Windows: CMake-generated config.h defines AI_V4MAPPED as 0 and overrides the
> Winsock value
> ------------------------------------------------------------------------------------------
>
> Key: THRIFT-6249
> URL: https://issues.apache.org/jira/browse/THRIFT-6249
> Project: Thrift
> Issue Type: Bug
> Components: Build Process, C++ - Library
> Reporter: Sylwester Lachiewicz
> Priority: Major
>
> The MSVC CI job prints 158 copies of this warning while building the C++
> library, its tests, the generated-code test projects and the tutorial
> (example: [MSVC run on
> master|https://github.com/apache/thrift/actions/runs/34762947299]):
> {noformat}
> C:\build\thrift\config.h(50,9): warning C4005: 'AI_V4MAPPED': macro
> redefinition [C:\build\lib\cpp\thrift.vcxproj]
> {noformat}
> The location is the generated config.h, so the Winsock definition comes first
> and config.h wins. {{Thrift.h}} includes {{PlatformSocket.h}}
> ({{winsock2.h}}, which pulls in {{ws2def.h}} with {{AI_V4MAPPED 0x00000800}})
> and only then {{thrift-config.h}}.
> h3. Cause
> [build/cmake/ConfigureChecks.cmake:76|https://github.com/apache/thrift/blob/master/build/cmake/ConfigureChecks.cmake#L76]
> looks for the symbol with {{check_symbol_exists(AI_V4MAPPED
> "sys/types.h;sys/socket.h;netdb.h" ...)}}. Those headers do not exist on
> Windows, so the check fails and {{#cmakedefine AI_V4MAPPED 0}} in
> [build/cmake/config.h.in:50|https://github.com/apache/thrift/blob/master/build/cmake/config.h.in#L50]
> becomes {{#define AI_V4MAPPED 0}}.
> The check came in with [PR #3737|https://github.com/apache/thrift/pull/3737]
> ([405a95fda|https://github.com/apache/thrift/commit/405a95fdaf450dd9200fccc9d6f7630f3f09451e]),
> which replaced the AI_ADDRCONFIG check with one for AI_V4MAPPED for OpenBSD.
> It is on master since 2026-08-28 and not in 0.24.0. configure.ac carries the
> same {{AC_CHECK_DECL}}, but autotools does not build the Windows library, so
> only the CMake path is affected.
> h3. Effect
> On Windows the flag is 0 in every translation unit that sees config.h after
> the Winsock headers, so the getaddrinfo calls that ask for IPv4-mapped
> addresses silently stop doing so:
> *
> [lib/cpp/src/thrift/transport/TServerSocket.cpp:449|https://github.com/apache/thrift/blob/master/lib/cpp/src/thrift/transport/TServerSocket.cpp#L449]
> *
> [lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp:377|https://github.com/apache/thrift/blob/master/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp#L377]
> * the default flags in
> [lib/cpp/src/thrift/transport/TSocketUtils.h:140|https://github.com/apache/thrift/blob/master/lib/cpp/src/thrift/transport/TSocketUtils.h#L140]
> Windows has supported AI_V4MAPPED since Vista, so the fallback is wrong
> there, not merely noisy.
> Same class of defect as
> [THRIFT-4077|https://issues.apache.org/jira/browse/THRIFT-4077]
> (AI_ADDRCONFIG redefined through PlatformSocket.h, fixed in 0.11.0).
> [THRIFT-6191|https://issues.apache.org/jira/browse/THRIFT-6191] is about the
> same flag but a different problem, the POSIX mismatch between server and
> client resolution.
> h3. Fix options
> * Run the check against the Windows headers on WIN32
> ({{winsock2.h;ws2tcpip.h}}, matching PlatformSocket.h), or
> * emit the fallback only when the symbol is still undefined, by wrapping the
> {{#cmakedefine}} in {{#ifndef AI_V4MAPPED}}.
> The warning count is the regression check: the MSVC job on master prints 158
> C4005 for this macro today and should print none.
> _This issue was created with AI assistance._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)