2017-09-15 94 views
0

我試圖在Ubuntu上的Codeblocks 16.01中編譯此代碼,但它返回了錯誤消息未定義引用'curl_easy_init'無法在Ubuntu中使用Codeblocks IDE編譯libcurl

但是,當我運行在終端gcc -L/usr/lib/x86_64-linux-gnu main.c -o curl -lcurl不會返回任何錯誤。

我該如何解決這個問題?

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

void fileUpload() 
{ 
    CURL *curl; 
    CURLcode res; 

    curl = curl_easy_init(); 
    if(curl) { 
     curl_easy_setopt(curl, CURLOPT_URL,"http://test1:[email protected]/geoserver/rest/layers.xml"); 
     /* 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)); 

     FILE* file = fopen("layers.txt", "w"); 

     curl_easy_setopt(curl, CURLOPT_WRITEDATA, file) ; 

     /* 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); 

     fclose(file); 
    } 
} 


int main() { 

    //Call to the method that charge the url content to a file with all the layers. 
    fileUpload(); 
    return 0; 
} 

回答

0

我想你已經忘了告訴代碼塊與libcurl鏈接:

  • 編譯選項...
  • 連接器設置
  • 添加(按鈕)
  • 輸入curl

在imag中看到它es在這裏:https://stackoverflow.com/a/5881751/1212012

+0

謝謝,最後我通過在鏈接器設置 - >其他鏈接器選項中添加-lcurl – Ryon94