英文:
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 "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;
}
答案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 "c:\curl\include" -L "c:\curl\lib" -o simple.exe simple.c -lcurl
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论