You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下Libcurl C程序运行失败的问题排查求助

libcurl运行时错误排查问题

环境准备

  • 下载32位版本的libcurl(Windows平台)
  • 将解压后的文件夹放置到%USERPROFILE%\Downloads路径下,命名为curl

测试代码

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

int main()
{
    printf("Running...");
    CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
    printf("%d\n", code);
    if (code != 0)
        return 1;
    char *version = curl_version();
    printf("%s", version);
    curl_global_cleanup();
    printf("Done\n");
    return 0;
}

编译操作(32位MinGW gcc)

执行以下编译命令,返回errorlevel为0,说明编译成功:

gcc libcurl_test.c -o libcurl_test.exe -I %USERPROFILE%\Downloads\curl\include -L %USERPROFILE%\Downloads\curl\lib -lcurl

echo %errorlevel%
0

运行异常情况

运行生成的可执行文件后,程序异常退出,errorlevel为-1073741515:

.\libcurl_test.exe

echo %errorlevel%
-1073741515

预期运行结果:

.\libcurl_test.exe
Running...0
Done

echo %errorlevel%
0

注释curl代码后的正常运行

将代码中curl相关函数注释后,重新编译运行,程序可正常执行:

修改后的代码:

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

int main()
{
    printf("Running...");
    // CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
    // printf("%d\n", code);
    // if (code != 0)
    //     return 1;
    // char *version = curl_version();
    // printf("%s", version);
    // curl_global_cleanup();
    printf("Done\n");
    return 0;
}

编译运行结果:

gcc libcurl_test.c -o libcurl_test.exe -I C:\Users\Caleb\Downloads\curl\include -L C:\Users\Caleb\Downloads\curl\lib -lcurl

echo %errorlevel%
0

.\libcurl_test.exe
Running...Done

echo %errorlevel%
0

请问我遗漏了什么?


内容的提问来源于stack exchange,提问作者praise_the_sun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 12:51:36