Cześć, mam problem od kilku dni głowie się nad ściąganiem w c++. Próbowałem curlem i :
[Linker error] undefined reference to `_imp__curl_easy_setopt'
Może mi ktoś podać jakieś rozwiązanie? Prosty działający przykład :*
Cześć, mam problem od kilku dni głowie się nad ściąganiem w c++. Próbowałem curlem i :
[Linker error] undefined reference to `_imp__curl_easy_setopt'
Może mi ktoś podać jakieś rozwiązanie? Prosty działający przykład :*
Dodaj bibliotekę do konsolidacji (linkier)
Nic to nie daje, tylko ignoruje błędy - kompilacja nie jest zakończona.
jak masz "linker error" to znaczy, że kompilacja się powiodła, a na etapie łączenia jet błąd. Masz niezdefiniowany (ale zadeklarowany) symbol "_imp__curl_easy_setopt".
Albo brakuje ci definicji tego symbolu w twoim kodzie, albo zapomniałeś dodać bibliotekę, która zawiera ten symbol.
edit:
popatrz na http://curl.haxx.se/docs/faq.html punkt 5.7
When building an application that uses the static libcurl library, you must add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for dynamic import symbols. If you're using Visual Studio, you need to instead add CURL_STATICLIB in the "Preprocessor Definitions" section.
Dalej nic, mój kod to tak naprawdę przykład z internetu - chciałem po prostu sprawdzić działanie curl'a.
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string>
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
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;
}
Kompilator Log's:
Kompilator: Default compiler
Building Makefile: "D:\Dev-Cpp\Makefile.win"
Wykonywanie make...
make.exe -f "D:\Dev-Cpp\Makefile.win" all
g++.exe main.o -o "test1.exe" -L"D:/Dev-Cpp/lib" -DCURL_STATICLIB - curl
g++.exe: curl: No such file or directory
g++.exe: -E required when input is from standard input
make.exe: *** [test1.exe] Error 1
Wykonanie zakończone
Edit@@@
Dobra pobieranie działa, wystarczyło dołączyć libcurl.dll ;P
Chce do tego dodać postęp pobierania, myślałem nad tym by pobrać całkowity rozmiar pliku po czym pobrać aktualną ilość KB po czym wyliczyć procent, może być? ;)