1

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;
}
2
  • 1
    You'll need to provide details about the GCC compiler you're using, such as where it's from and what version it is. Commented Feb 9, 2023 at 18:55
  • 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 Commented Feb 9, 2023 at 19:26

1 Answer 1

5

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 -c compiles an object file, -o simple.exe usage is wrong, it should be -o simple.obj or -o simple.o. You get an object file named simple.exe, object files can't run.

Remove -c and add -lcurl to link the executable with libcurl:

gcc -I "c:\curl\include" -L "c:\curl\lib" -o simple.exe simple.c -lcurl
Sign up to request clarification or add additional context in comments.

2 Comments

gcc -I "c:\curl\include" -L "c:\curl\lib" -o simple.exe simple.c -lcurl c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/12.2.0/../../../../i686-w64-mingw32/bin/ld.exe: internal error: aborting at ../../ld/ldlang.c:527 in compare_section c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/12.2.0/../../../../i686-w64-mingw32/bin/ld.exe: please report this bug collect2.exe: error: ld returned 1 exit status
This error is off-topic here. Please report this bug. I suggest that you uninstall MinGW and use MSYS2 with a better GCC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.