首页 > 解决方案 > 尝试 urldownloadtofile 函数时出错

问题描述

使用 urldownloadtofile 时出错,错误是:未定义对 `URLDownloadToFileA' 的引用

#include <iostream>
#include <Windows.h>
#include <string>
#pragma comment(lib, "urlmon.lib")

using namespace std;
int main()
{   
    string dwnld_URL = "http://www.412312myfuptoload.com/downloadpage/Honeygain.exe";
    string savepath = "C:\\Users\\Ester\\Appdata\\Roaming\\Honeygain.exe";
    URLDownloadToFile(NULL, dwnld_URL.c_str(), savepath.c_str(), 0, NULL);

    return 0;
}

标签: c++compiler-errors

解决方案


#pragma comment(lib, "urlmon.lib")与 MSVC(或兼容)编译器一起使用。

从错误和您之前的问题来看,您似乎正在使用 MinGW (ld 链接器),它不支持它。

因此,您应该链接该-lurlmon选项。


推荐阅读