更改为win下跨平台的程序

#include <winsock2.h>

void init_winsock()
{
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
    wVersionRequested = MAKEWORD(2,2);
    err = WSAStartup( wVersionRequested, &wsaData );
    if ( err != 0 ) {   
        return;
    }
    if ( LOBYTE( wsaData.wVersion ) != 2 ||
         HIBYTE( wsaData.wVersion ) != 2 ) {
        WSACleanup();
        return;
    }
}
CmakeLists.txt  添加 link_libraries(-lws2_32)

-------------------------

WSADATA wsaData;

if (WSAStartup(MAKEWORD(1,1), &wsaData))
return 0;





posted @ 2020-06-29 12:13  MoonXu  阅读(178)  评论(0编辑  收藏  举报