Compiling C source code for Windows using libcurl using mingw32 and libcurl32. The command line below:
gcc -c -I "c:\curl\include" -L "c:\curl\lib" -o simple.exe simple.c
The compilation runs successfully, generating the exe file. But when I try to run it I get the message:
Unsupported 16-bit application. The program or feature "simple.exe" cannot start or run due to an incompatibility with 64-bit versions of Windows.
gcc (MinGW-W64 i686-ucrt-posix-dwarf, built by Brecht Sanders) 12.2.0
curl 7.83.1 (Windows) libcurl/7.83.1 Schannel Release-Date: 2022-05-13 Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp Features: AsynchDNS HSTS IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI UnixSockets
My code:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* 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));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}