I've tried to find the answer for this here and in other forums as well, but I haven't found anything.
I'm doing a project for college and I need to use libcurl. I can use it easily in Debian, after I installed libcurl3-dev and using -lcurl when I compile. But in Windows, it just doesn't work.
I am using Visual Studio Code, with C/C++ extensions installed. The header <curl/curl.h> is recognized, but when I compile, it returns me an error:
c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\mathe\AppData\Local\Temp\ccw32OmO.o:CatchDate.c:(.text+0x3db): undefined reference to `__imp_curl_easy_init'
c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\mathe\AppData\Local\Temp\ccw32OmO.o:CatchDate.c:(.text+0x423): undefined reference to `__imp_curl_easy_setopt'
c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\mathe\AppData\Local\Temp\ccw32OmO.o:CatchDate.c:(.text+0x477): undefined reference to `__imp_curl_easy_setopt'
c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\mathe\AppData\Local\Temp\ccw32OmO.o:CatchDate.c:(.text+0x49b): undefined reference to `__imp_curl_easy_setopt'
c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\mathe\AppData\Local\Temp\ccw32OmO.o:CatchDate.c:(.text+0x4ae): undefined reference to `__imp_curl_easy_perform'
c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\mathe\AppData\Local\Temp\ccw32OmO.o:CatchDate.c:(.text+0x4d4): undefined reference to `__imp_curl_easy_cleanup'
c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text+0x46): undefined reference to `WinMain'
If I compile directly using cmd with -lcurl, the error is:
c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcurl
collect2.exe: error: ld returned 1 exit status
The code is in https://github.com/matheusxreis/hospital-record-system/tree/testes
The part where I use libcurl is:
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
};
CURL *curl = curl_easy_init();
FILE *fp;
fp = fopen("pacientes/dates.txt", "a");
curl_easy_setopt(curl, CURLOPT_URL, complete_link);
fprintf(fp, "\nNOME: %s\n", nome);
fprintf(fp, "ENDEREĆO:");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_perform(curl);
fprintf(fp, "******\n");
curl_easy_cleanup(curl);
fclose(fp);
Maybe I am doing something wrong, but I don't know what. This is my first time using libcurl.