0

I've got error during compilation. MSVS don't see any problems. But compiller.. Help me, pls.

Errors:

Error LNK1120 unresolved external elements 7 CryptoCAT C: \ Users \ alexx \ onedrive \ documents \ visual studio 2015 \ Projects \ CryptoCAT \ Debug \ CryptoCAT.exe 1

Error LNK2019 unresolved external reference to the symbol __imp__connect @ 12 as a function of "char * __cdecl heh (char *, char *)" (heh @@ YAPADPAD0 @ Z?)

Error LNK2019 unresolved external reference to the symbol __imp__htons @ 4 as a function of "char * __cdecl heh (char *, char *)" (heh @@ YAPADPAD0 @ Z?)

Error LNK2019 unresolved external reference to the symbol __imp__inet_addr @ 4 as a function of "char * __cdecl heh (char *, char *)" (heh @@ YAPADPAD0 @ Z?)

Error LNK2019 unresolved external reference to the symbol __imp__recv @ 16 as a function of "char * __cdecl heh (char *, char *)" (heh @@ YAPADPAD0 @ Z?)

Error LNK2019 unresolved external reference to the symbol __imp__send @ 16 as a function of "char * __cdecl heh (char *, char *)" (heh @@ YAPADPAD0 @ Z?)

Error LNK2019 unresolved external reference to the symbol __imp__socket @ 12 as a function of "char * __cdecl heh (char *, char *)" (heh @@ YAPADPAD0 @ Z?)

 #include "stdafx.h"
    #include <stdio.h>
    #include <winsock2.h>
    #include <windows.h>
    char * heh(char *ip, char *msg) {
        int sock;
        struct sockaddr_in server;
        char server_reply[2000];
        sock = socket(AF_INET, SOCK_STREAM, 0);
        if (sock == -1)
        {
            return "nosocket";
        }
        server.sin_addr.s_addr = inet_addr(ip);
        server.sin_family = AF_INET;
        server.sin_port = htons(4567);
        if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0)
        {
            return "connectfail";
        }
        if (send(sock, msg, strlen(msg), 0) < 0)
        {
            return "sendfail";
        }
        if (recv(sock, server_reply, 2000, 0) < 0)
        {
            return "recv failed";
        }
        return server_reply;
        closesocket(sock);
    }
Alex
  • 1
  • 1
    Project > Properties > Linker > Input > Additional Dependencies setting, add ws2_32.lib – Hans Passant Nov 06 '16 at 16:56
  • LNK2019 unresolved external reference is an error coming from the linker (clue 1: the LNK prefix on the error code; clue 2: unresolved external). The normal fix to this type of error is to ensure that the appropriate library has been added to the project. Hans, already gave the information on where and what library to add. Just wanted to give a bit more background. – thurizas Nov 06 '16 at 16:59

0 Answers0