Commit 68f4547b authored by Guolin Ke's avatar Guolin Ke
Browse files

fix build error in mingw on windows

parent 88b84436
...@@ -159,7 +159,7 @@ public: ...@@ -159,7 +159,7 @@ public:
} }
else { else {
const size_t idx = random.NextInt(0, line_idx + 1); const size_t idx = random.NextInt(0, line_idx + 1);
if (idx < sample_cnt) { if (idx < static_cast<size_t>(sample_cnt)) {
out_sampled_data->operator[](idx) = std::string(buffer, size); out_sampled_data->operator[](idx) = std::string(buffer, size);
} }
} }
...@@ -184,7 +184,7 @@ public: ...@@ -184,7 +184,7 @@ public:
} }
INDEX_T SampleAndFilterFromFile(const std::function<bool(INDEX_T)>& filter_fun, std::vector<INDEX_T>* out_used_data_indices, INDEX_T SampleAndFilterFromFile(const std::function<bool(INDEX_T)>& filter_fun, std::vector<INDEX_T>* out_used_data_indices,
Random& random, size_t sample_cnt, std::vector<std::string>* out_sampled_data) { Random& random, INDEX_T sample_cnt, std::vector<std::string>* out_sampled_data) {
INDEX_T cur_sample_cnt = 0; INDEX_T cur_sample_cnt = 0;
out_used_data_indices->clear(); out_used_data_indices->clear();
INDEX_T total_cnt = ReadAllAndProcess( INDEX_T total_cnt = ReadAllAndProcess(
...@@ -199,7 +199,7 @@ public: ...@@ -199,7 +199,7 @@ public:
} }
else { else {
const size_t idx = random.NextInt(0, out_used_data_indices->size()); const size_t idx = random.NextInt(0, out_used_data_indices->size());
if (idx < sample_cnt) { if (idx < static_cast<size_t>(sample_cnt) ) {
out_sampled_data->operator[](idx) = std::string(buffer, size); out_sampled_data->operator[](idx) = std::string(buffer, size);
} }
} }
...@@ -286,7 +286,7 @@ public: ...@@ -286,7 +286,7 @@ public:
INDEX_T ReadPartAndProcessParallel(const std::vector<INDEX_T>& used_data_indices, const std::function<void(INDEX_T, const std::vector<std::string>&)>& process_fun) { INDEX_T ReadPartAndProcessParallel(const std::vector<INDEX_T>& used_data_indices, const std::function<void(INDEX_T, const std::vector<std::string>&)>& process_fun) {
return ReadAllAndProcessParallelWithFilter(process_fun, return ReadAllAndProcessParallelWithFilter(process_fun,
[&used_data_indices](INDEX_T used_cnt ,INDEX_T total_cnt) { [&used_data_indices](INDEX_T used_cnt ,INDEX_T total_cnt) {
if (used_cnt < used_data_indices.size() && total_cnt == used_data_indices[used_cnt]) { if (static_cast<size_t>(used_cnt) < used_data_indices.size() && total_cnt == used_data_indices[used_cnt]) {
return true; return true;
} }
else { else {
......
...@@ -25,3 +25,10 @@ if(USE_MPI) ...@@ -25,3 +25,10 @@ if(USE_MPI)
TARGET_LINK_LIBRARIES(_lightgbm ${MPI_CXX_LIBRARIES}) TARGET_LINK_LIBRARIES(_lightgbm ${MPI_CXX_LIBRARIES})
endif(USE_MPI) endif(USE_MPI)
if(WIN32)
TARGET_LINK_LIBRARIES(lightgbm Ws2_32)
TARGET_LINK_LIBRARIES(_lightgbm Ws2_32)
TARGET_LINK_LIBRARIES(lightgbm IPHLPAPI)
TARGET_LINK_LIBRARIES(_lightgbm IPHLPAPI)
endif(WIN32)
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#ifdef USE_SOCKET #ifdef USE_SOCKET
#if defined(_WIN32) #if defined(_WIN32)
#ifdef _MSC_VER
#define NOMINMAX #define NOMINMAX
#endif
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <iphlpapi.h> #include <iphlpapi.h>
...@@ -46,6 +48,35 @@ const int INVALID_SOCKET = -1; ...@@ -46,6 +48,35 @@ const int INVALID_SOCKET = -1;
#endif #endif
#ifdef _WIN32
#ifndef _MSC_VER
// not using visual studio in windows
inline int inet_pton(int af, const char *src, void *dst)
{
struct sockaddr_storage ss;
int size = sizeof(ss);
char src_copy[INET6_ADDRSTRLEN + 1];
ZeroMemory(&ss, sizeof(ss));
/* stupid non-const API */
strncpy(src_copy, src, INET6_ADDRSTRLEN + 1);
src_copy[INET6_ADDRSTRLEN] = 0;
if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) {
switch (af) {
case AF_INET:
*(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr;
return 1;
case AF_INET6:
*(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr;
return 1;
}
}
return 0;
}
#endif
#endif
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment