diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cdbf54513a9..d5ebeb05932d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -327,9 +327,9 @@ endif() if(WIN32) include(CheckSymbolExists) list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32") - check_symbol_exists(inet_pton "ws2tcpip.h" INET_PTON_FOUND) - if(INET_PTON_FOUND) - add_definitions(-DHAS_INET_PTON) + check_symbol_exists(inet_pton "ws2tcpip.h" WIN32_INET_PTON_FOUND) + if(WIN32_INET_PTON_FOUND) + add_definitions(-DWIN32_HAS_INET_PTON) endif() endif() diff --git a/R-package/configure.win b/R-package/configure.win index d7f75f972771..4d20644778cd 100755 --- a/R-package/configure.win +++ b/R-package/configure.win @@ -70,6 +70,34 @@ then LGB_CPPFLAGS="${LGB_CPPFLAGS} -DMM_MALLOC=1" fi +############### +# INET_PTON # +############### + +ac_inet_pton="no" + +cat > conftest.cpp < +#endif +int main() { + #ifdef _WIN32 + void* p = inet_pton; + #endif + return 0; +} +EOL + +${CXX} ${CXXFLAGS} ${CPPFLAGS} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_inet_pton="yes" +rm -f ./conftest +rm -f ./conftest.cpp +echo "checking whether INET_PTON works...${ac_inet_pton}" + +if test "${ac_inet_pton}" = "yes"; +then + LGB_CPPFLAGS="${LGB_CPPFLAGS} -DWIN32_HAS_INET_PTON=1" +fi + # Generate Makevars.win from Makevars.win.in sed -e \ "s/@LGB_CPPFLAGS@/$LGB_CPPFLAGS/" \ diff --git a/src/network/socket_wrapper.hpp b/src/network/socket_wrapper.hpp index 57d97973d01e..f8e6ee62cbe7 100644 --- a/src/network/socket_wrapper.hpp +++ b/src/network/socket_wrapper.hpp @@ -60,8 +60,8 @@ const int INVALID_SOCKET = -1; #endif #ifdef _WIN32 -// existence of inet_pton is checked in CMakeLists.txt and stored in HAS_INET_PTON -#ifndef HAS_INET_PTON +// existence of inet_pton is checked in CMakeLists.txt and stored in WIN32_HAS_INET_PTON +#ifndef WIN32_HAS_INET_PTON // not using visual studio in windows inline int inet_pton(int af, const char *src, void *dst) { struct sockaddr_storage ss;