Skip to content

Commit a0a617d

Browse files
shiyu1994jameslamb
authored andcommitted
add patch from #5159
1 parent 4498a89 commit a0a617d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,18 @@ if(WIN32 AND MINGW)
299299
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++")
300300
endif()
301301

302+
# Check if inet_pton is already available, to avoid conflicts with the implementation in LightGBM.
303+
# As of 2022, MinGW started including a definition of inet_pton.
304+
if(WIN32)
305+
include(CheckSymbolExists)
306+
list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
307+
check_symbol_exists(inet_pton "ws2tcpip.h" WIN_INET_PTON_FOUND)
308+
if(WIN_INET_PTON_FOUND)
309+
add_definitions(-DWIN_HAS_INET_PTON)
310+
endif()
311+
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "ws2_32")
312+
endif()
313+
302314
if(MSVC)
303315
SET(variables
304316
CMAKE_C_FLAGS_DEBUG

src/network/socket_wrapper.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ const int INVALID_SOCKET = -1;
6060
#endif
6161

6262
#ifdef _WIN32
63-
#ifndef _UCRT
64-
// Recent MinGW has inet_pton, which then causes compiler error in
65-
// combination with this replacement.
66-
#ifndef _MSC_VER
67-
// not using visual studio in windows
63+
// existence of inet_pton is checked in CMakeLists.txt and configure.win, then stored in WIN_HAS_INET_PTON
64+
#ifndef WIN_HAS_INET_PTON
6865
inline int inet_pton(int af, const char *src, void *dst) {
6966
struct sockaddr_storage ss;
7067
int size = sizeof(ss);
@@ -89,7 +86,6 @@ inline int inet_pton(int af, const char *src, void *dst) {
8986
}
9087
#endif
9188
#endif
92-
#endif
9389

9490
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
9591
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))

0 commit comments

Comments
 (0)