2014-09-25 31 views
0

我使用Qtcreator未解決的符號鏈接在Qt中使用libcurl的程序

當我嘗試編譯我的解決方案我不斷收到這個錯誤(這是從我的Qtcreator)時:

main.obj:-1: error: LNK2019: unresolved external symbol __imp__curl_easy_strerror referenced in function _main 
main.obj:-1: error: LNK2019: unresolved external symbol __imp__curl_easy_strerror referenced in function _main 
main.obj:-1: error: LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function _main 
main.obj:-1: error: LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function _main 
main.obj:-1: error: LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function _main 
debug\test.exe:-1: error: LNK1120: 5 unresolved externals 

來源(這是從他們的curlhttp://curl.haxx.se/libcurl/c/example.html一個sample.c文件):

#include <stdio.h> 
#include <curl/curl.h> 

int main(void) 
{ 
    CURL *curl; 
    CURLcode res; 

    curl = curl_easy_init(); 
    if(curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); 
    /* example.com is redirected, so we tell libcurl to follow redirection */ 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 

    /* Perform the request, res will get the return code */ 
    res = curl_easy_perform(curl); 
    /* Check for errors */ 
    if(res != CURLE_OK) 
     fprintf(stderr, "curl_easy_perform() failed: %s\n", 
       curl_easy_strerror(res)); 

    /* always cleanup */ 
    curl_easy_cleanup(curl); 
    } 
    return 0; 
    } 

我將此添加到我的.pro文件

INCLUDEPATH = C:\Users\Uporabnik\Desktop\curl-7.38.0\curl-7.38.0\include 
+1

您可能缺少.pro文件中的LIBS + ='。請將您的.pro添加到問題中,以及libcurl的路徑和失敗的編譯命令。 – hyde 2014-09-25 15:35:05

+0

它沒有幫助 – Seba 2014-09-25 15:42:59

+0

什麼沒有幫助? – hyde 2014-09-25 15:44:00

回答

0

你需要在你的.pro文件是這樣的:

LIBS += -lcurl -LC:/Users/Uporabnik/Desktop/curl-7.38.0/curl-7.38.0 

-l告訴應該用這個名字了圖書館,並-L告訴這個目錄應該用於庫搜索時(在除了已經搜索過的其他dirs)。在qmake,這也將做正確的事情,即使MSVC工具鏈,我相信,而且不僅Mingw gcc

請注意,確切的路徑和lib名稱是我的一部分猜測,您可能需要調整它們。

+0

現在我得到這個錯誤:-1:錯誤:LNK1104:無法打開文件'curl.lib' – Seba 2014-09-25 16:51:06

+0

你在哪裏有'curl.lib'文件,在你的磁盤? – hyde 2014-09-25 17:12:19

+0

我沒有curl.lib文件。我從http://curl.haxx.se/download.html下載了.zip文件,裏面不是.lib文件。 - curl-7.38.0 – Seba 2014-09-25 20:18:24

相關問題