Compiling C source code for Windows using libcurl

huangapple go评论49阅读模式
英文:

Compiling C source code for Windows using libcurl

问题

以下是代码部分的翻译:

Compiling C source code for Windows using libcurl using mingw32 and libcurl32. The command line below:
使用mingw32和libcurl32编译C源代码以在Windows上使用libcurl。以下是命令行:

gcc -c -I "c:\curl\include" -L "c:\curl\lib" -o simple.exe simple.c
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:
编译成功,生成了exe文件。但当我尝试运行它时,我收到以下消息:

Unsupported 16-bit application. The program or feature "simple.exe" cannot start or run due to an incompatibility with 64-bit versions of Windows.
不支持的16位应用程序。由于与64位版本的Windows不兼容,程序或功能"simple.exe"无法启动或运行。

gcc (MinGW-W64 i686-ucrt-posix-dwarf, built by Brecht Sanders) 12.2.0
gcc(由Brecht Sanders构建的MinGW-W64 i686-ucrt-posix-dwarf,版本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
curl 7.83.1 (Windows) libcurl/7.83.1 Schannel 发布日期:2022-05-13 协议:dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp 功能: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;
}

以上是您提供的代码部分的翻译。如果您有其他问题或需要进一步帮助,请随时告诉我。

英文:

Compiling C source code for Windows using libcurl using mingw32 and libcurl32. The command line below:

gcc -c -I &quot;c:\curl\include&quot; -L &quot;c:\curl\lib&quot; -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 &lt;stdio.h&gt;
#include &lt;curl/curl.h&gt;

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, &quot;https://example.com&quot;);
    /* 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, &quot;curl_easy_perform() failed: %s\n&quot;,
              curl_easy_strerror(res));

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

答案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编译一个目标文件,-o simple.exe的用法不正确,应该是-o simple.obj-o simple.o。你会得到一个名为simple.exe的目标文件,目标文件无法运行。

去掉-c,并添加-lcurl来链接可执行文件与libcurl:

gcc -I "c:\curl\include" -L "c:\curl\lib" -o simple.exe simple.c -lcurl
英文:

> 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 &quot;c:\curl\include&quot; -L &quot;c:\curl\lib&quot; -o simple.exe simple.c -lcurl

huangapple
  • 本文由 发表于 2023年2月10日 02:40:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75403072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定