2017-09-15 10 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で実行してもエラーは返されません。

どうすればこの問題を解決できますか?

私はあなたが libcurlとリンクするコードブロックを伝えるのを忘れてたと思う
#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

  • リンカが
  • 追加(ボタン)
  • curl
  • を入力する設定ビルドオプション...

imagで表示ここでは、https://stackoverflow.com/a/5881751/1212012

+0

ありがとうございます。ありがとうございました。最後に、リンカ設定 - >その他のリンカオプションで-lcurlを追加して動作させています。 – Ryon94

関連する問題