Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在Dev+中链接libws2_32.a进行套接字编程+;_C++_Linker - Fatal编程技术网

C++ 如何在Dev+中链接libws2_32.a进行套接字编程+;

C++ 如何在Dev+中链接libws2_32.a进行套接字编程+;,c++,linker,C++,Linker,我正在使用Dev++,根据我阅读的一篇关于套接字编程的教程,我需要为我的项目链接到libws2_32.a 我不知道该怎么做。有人能解释一下吗 这是我的密码: //CONNECT TO REMOTE HOST (CLIENT APPLICATION) //Include the needed header files. //Don't forget to link libws2_32.a to your program as well #include <winsock.h> #pra

我正在使用Dev++,根据我阅读的一篇关于套接字编程的教程,我需要为我的项目链接到
libws2_32.a

我不知道该怎么做。有人能解释一下吗

这是我的密码:

//CONNECT TO REMOTE HOST (CLIENT APPLICATION)
//Include the needed header files.
//Don't forget to link libws2_32.a to your program as well
#include <winsock.h>
#pragma comment(lib,"libwsock32.a")
SOCKET s; //Socket handle

//CONNECTTOHOST – Connects to a remote host
bool ConnectToHost(int PortNo, char* IPAddress)
{
    //Start up Winsock…
    WSADATA wsadata;

    int error = WSAStartup(0x0202, &wsadata);

    //Did something happen?
    if (error)
        return false;

    //Did we get the right Winsock version?
    if (wsadata.wVersion != 0x0202)
    {
        WSACleanup(); //Clean up Winsock
        return false;
    }

    //Fill out the information needed to initialize a socket…
    SOCKADDR_IN target; //Socket address information

    target.sin_family = AF_INET; // address family Internet
    target.sin_port = htons (PortNo); //Port to connect on
    target.sin_addr.s_addr = inet_addr (IPAddress); //Target IP

    s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); //Create socket
    if (s == INVALID_SOCKET)
    {
        return false; //Couldn't create the socket
    }  

    //Try connecting...

    if (connect(s, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR)
    {
        return false; //Couldn't connect
    }
    else
        return true; //Success
}

//CLOSECONNECTION – shuts down the socket and closes any connection on it
void CloseConnection ()
{
    //Close the socket if it exists
    if (s)
        closesocket(s);

    WSACleanup(); //Clean up Winsock
}

转到项目选项->参数->链接器->添加库并添加所需的库文件-在您的示例中-
libws2\u 32。a

i linked now只是一个错误:[链接器错误]未定义的引用`WinMain@16'它想要什么?@Dest完全不同的问题-新问题。我可以每20秒问一次问题,如果你知道我如何解决这个问题,请重播me@Dest我不确定,这就是为什么我让你问一个新问题。我认为这与子系统有关。尝试用谷歌搜索
子系统窗口
子系统控制台
——这两个选项可能会告诉编译器要使用哪个入口点(main或winmain)。希望有帮助,对不起,我不能提供更多细节。
[Linker error] undefined reference to `WSAStartup@8'