C - Undefined Link to WSAStartup @ 8 '

I use Code :: Blocks, MinGW and Windows. I am trying to initialize winsock so that I can work on a project. I keep getting the error Undefined Reference to WSAStartup@8Does anyone know how to fix this?

#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>

#pragma comment(lib,"ws2_32.lib")

int main(int argc , char *argv[]){
    WSADATA wsa;
    int output;

    output=WSAStartup(MAKEWORD(2,2),&wsa);
    if(output != 0) {
        printf("Startup failed %d\n", output);
        return 1;
    } else {
        printf("Initialized");
        return 0;
    }

}
+4
source share
4 answers

. , , , , , , . winsock -lws2_32, .

gcc prog.c -o prog -lws2_32
+10

, ( Microsoft), #pragma comment(lib,"ws2_32.lib"). :

  • GCC (.. MinGW), , .
  • MinGW ( , GCC (, ?) ) "ws2_32.lib"; ( ws2_32.dll), "libws2_32.a".

, MSVC ; , (), tinky_winky:

gcc prog.c -o prog.exe [...other .c and .o files...] -lws2_32 ...

( , , ).

+1

: , funtion, , . lib MINGW ( C:/MinGW/lib); , , Dlib regconite missing lib. wxWidgets Code:: Blocks

0
source

You can check yours compiler options, add -lws2_32in add linker options when linking. I use TDM-GCC, works well after that.

0
source

Source: https://habr.com/ru/post/1621016/


All Articles