Reputation: 2609
I'm making a program in C++ (using netbeans 7.4 with mingw). I downloaded a code file from the internet which uses cURL Library so I setup cURL then I tried to run the code but it is giving me the following error:
mkdir -p dist/Debug/MinGW_TDM-Windows
g++ -o dist/Debug/MinGW_TDM-Windows/nb-cppmainproject build/Debug/MinGW_TDM-Windows/curldnld.o
build/Debug/MinGW_TDM-Windows/curldnld.o: In function `main':
F:\Users\Amol-2\Desktop\Imp Docs\C++ apps\NB-CppMainProject/curldnld.c:18: undefined reference to `_imp__curl_easy_init'
F:\Users\Amol-2\Desktop\Imp Docs\C++ apps\NB-CppMainProject/curldnld.c:21: undefined reference to `_imp__curl_easy_setopt'
F:\Users\Amol-2\Desktop\Imp Docs\C++ apps\NB-CppMainProject/curldnld.c:22: undefined reference to `_imp__curl_easy_setopt'
F:\Users\Amol-2\Desktop\Imp Docs\C++ apps\NB-CppMainProject/curldnld.c:23: undefined reference to `_imp__curl_easy_setopt'
F:\Users\Amol-2\Desktop\Imp Docs\C++ apps\NB-CppMainProject/curldnld.c:24: undefined reference to `_imp__curl_easy_perform'
F:\Users\Amol-2\Desktop\Imp Docs\C++ apps\NB-CppMainProject/curldnld.c:26: undefined reference to `_imp__curl_easy_cleanup'
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW_TDM-Windows/nb-cppmainproject.exe] Error 1
make.exe[2]: Leaving directory `/f/Users/Amol-2/Desktop/Imp Docs/C++ apps/NB-CppMainProject'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/f/Users/Amol-2/Desktop/Imp Docs/C++ apps/NB-CppMainProject'
make.exe": *** [.build-impl] Error 2
code:
#include <stdio.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <string.h>
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}
int main(void) {
CURL *curl;
FILE *fp;
CURLcode res;
char *url = "http://localhost/aaa.txt";
char outfilename[FILENAME_MAX] = "C:\\bbb.txt";
curl = curl_easy_init();
if (curl) {
fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/aaa.txt");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(fp);
}
return 0;
}
I have tried to find other resources, but I can't solve the problem. What am I doing wrong?
Also how should I do this without using the cURL library?
Upvotes: 0
Views: 200
Reputation: 92432
You haven't linked the curl library. That is, your g++
call is missing a -lcurl
(and possibly a -Lpath_to_directory_with_curl_library
).
Upvotes: 1