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;
}
謝謝,最後我通過在鏈接器設置 - >其他鏈接器選項中添加-lcurl – Ryon94