首页 > 解决方案 > 使用带有 Mingw-w64 的 wininet 编译 c 源的链接器错误

问题描述

我在 Windows 上编译 c 源代码时遇到问题。我使用 wininet 的功能并得到一个链接器错误。
我使用这个版本 g++.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0

示例代码:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wininet.h>


int main (int argc, char **argv) 
{
    InternetOpen("WebReader", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); 
    return 0;
}

编译语句出现错误:

"C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\g++.exe" -lwininet -g test.c -o test.exe
C:\Users\peter\AppData\Local\Temp\ccfXocKI.o: In function `main':
D:\source\mingw\ShellHost/test.c:9: undefined reference to `_imp__InternetOpenA@20'
collect2.exe: error: ld returned 1 exit status

任何人都可以帮忙吗?

标签: mingw-w64

解决方案


您应该Wininet.lib按照InternetOpenA 文档所述链接(请参阅要求部分)。


推荐阅读