Fixed windows not linking

This commit is contained in:
Anonymous275 2021-02-26 20:47:31 +02:00 committed by Anonymous275
parent 7e6d5ce359
commit fab20276ff
4 changed files with 11 additions and 10 deletions

View File

@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.10)
project(Server) project(Server)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
if (WIN32)
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
endif ()
# this has to happen before -DDEBUG since it wont compile properly with -DDEBUG # this has to happen before -DDEBUG since it wont compile properly with -DDEBUG
include_directories("asio/asio/include") include_directories("asio/asio/include")
@ -20,12 +26,7 @@ if (UNIX)
message(STATUS "sanitize is ON") message(STATUS "sanitize is ON")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,thread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,thread")
endif (SANITIZE) endif (SANITIZE)
elseif (WIN32) endif()
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
endif ()
find_package(Boost REQUIRED COMPONENTS system thread) find_package(Boost REQUIRED COMPONENTS system thread)

View File

@ -23,7 +23,7 @@ inline void CloseSocketProper(int socket) {
#ifdef WIN32 #ifdef WIN32
#include <conio.h> #include <conio.h>
#include <winsock2.h> #include <winsock2.h>
inline void CloseSocketProper(int socket) { inline void CloseSocketProper(u_int64 socket) {
shutdown(socket, SD_BOTH); shutdown(socket, SD_BOTH);
closesocket(socket); closesocket(socket);
} }

View File

@ -79,5 +79,5 @@ int TClient::SecondsSinceLastPing() {
auto seconds = std::chrono::duration_cast<std::chrono::seconds>( auto seconds = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::high_resolution_clock::now() - mLastPingTime) std::chrono::high_resolution_clock::now() - mLastPingTime)
.count(); .count();
return seconds; return int(seconds);
} }

View File

@ -133,7 +133,7 @@ void TUDPServer::UDPSend(TClient& Client, std::string Data) const {
size_t len = Data.size(); size_t len = Data.size();
#endif // WIN32 #endif // WIN32
sendOk = sendto(mUDPSock, Data.c_str(), len, 0, (sockaddr*)&Addr, AddrSize); sendOk = sendto(mUDPSock, Data.c_str(), len, 0, (sockaddr*)&Addr, int(AddrSize));
#ifdef WIN32 #ifdef WIN32
if (sendOk == -1) { if (sendOk == -1) {
debug(("(UDP) Send Failed Code : ") + std::to_string(WSAGetLastError())); debug(("(UDP) Send Failed Code : ") + std::to_string(WSAGetLastError()));
@ -161,7 +161,7 @@ std::string TUDPServer::UDPRcvFromClient(sockaddr_in& client) const {
size_t clientLength = sizeof(client); size_t clientLength = sizeof(client);
std::array<char, 1024> Ret {}; std::array<char, 1024> Ret {};
#ifdef WIN32 #ifdef WIN32
int64_t Rcv = recvfrom(mUDPSock, Ret.data(), Ret.size(), 0, (sockaddr*)&client, (int*)&clientLength); int64_t Rcv = recvfrom(mUDPSock, Ret.data(), int(Ret.size()), 0, (sockaddr*)&client, (int*)&clientLength);
#else // unix #else // unix
int64_t Rcv = recvfrom(mUDPSock, Ret.data(), Ret.size(), 0, (sockaddr*)&client, (socklen_t*)&clientLength); int64_t Rcv = recvfrom(mUDPSock, Ret.data(), Ret.size(), 0, (sockaddr*)&client, (socklen_t*)&clientLength);
#endif // WIN32 #endif // WIN32