2009-04-27 61 views
0

我嘗試編譯這段代碼:爲什麼我得到:解析外部符號錯誤 - Visual C

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); 
} 

我得到這個連接錯誤: 鏈接...
mongoose.obj:錯誤LNK2019:無法解析外部符號_send @ 16在函數_push中引用

我在想什麼?它必須是一些lib或其他東西。我只是不記得我需要添加到我的鏈接。

回答

6

問題是鏈接器找不到send()函數。你已經包含了正確的頭文件,所以編譯器沒問題,但是你沒有連接正確的靜態庫。打開你的項目設置,轉到鏈接部分,以及適當的庫添加到在鏈接庫的列表。

[編輯]

正確的庫補充的是wsock32.lib

+0

added wsock32.lib http://www.codebase.com/support/kb/?article=C01060 – 2009-04-27 21:44:59

2

這並不完全清楚你實際問什麼問題。但它看起來像你的鏈接器無法找到任何地方被稱爲「發送」功能。

1

與正常錯誤的區別在於,您需要使用鏈接器而不是編譯器和代碼編輯器來解決它。

相關問題