Search code examples
externalsymbols

Why do I get: unresolved external symbol Error - C


I try to compile this code:

static uint64_t
push(int fd, SOCKET sock, SSL *ssl, const char *buf, uint64_t len)
{
    uint64_t    sent;
    int     n, k;

    sent = 0;
    while (sent < len) {

        /* How many bytes we send in this iteration */
        k = len - sent > INT_MAX ? INT_MAX : (int) (len - sent);

        if (ssl != NULL) {
            n = SSL_write(ssl, buf + sent, k);
        } else if (fd != -1) {
            n = write(fd, buf + sent, k);
        } else {
            n = send(sock, buf + sent, k, 0);
        }

        if (n < 0)
            break;

        sent += n;
    }

    return (sent);
}

And I get this linker error:

Linking...  
mongoose.obj : error LNK2019: unresolved external symbol _send@16 referenced in function _push

What am I missing? It must be some lib or something. I just don't remember what I need to add to my linking.


Solution

  • The problem is that the linker can't find the send() function. You've included the proper header files, so the compiler is ok, but you're not linking with the proper static libraries. Open up your project settings, go to the Linker section, and add the proper library to the list of libraries that are linked in.

    [Edit]

    The correct library to add is wsock32.lib.