【问题标题】:C++ wininet undefined reference even with -lwininet linker flag即使带有 -lwininet 链接器标志的 C++ wininet 未定义引用
【发布时间】:2017-07-28 12:02:21
【问题描述】:

我是 WinInet 新手,有以下简单的 C++ 代码:

void DoIt(std::string& host, std::string& username, std::string& password) {
    HINTERNET hInternet;
    HINTERNET hFtpSession;
    hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    if (hInternet == NULL) {
        std::cout << "Error: " << GetLastError();
    } else {
        hFtpSession = InternetConnect(hInternet, host.c_str(), INTERNET_DEFAULT_FTP_PORT, username.c_str(), password.c_str(), INTERNET_SERVICE_FTP, 0, 0);
        if (hFtpSession == NULL) {
            std::cout << "Error: " << GetLastError();
        } else {
            if (!FtpPutFile(hFtpSession, "C:\\temp\\ftp\\myFile.txt", "/myFile.txt", FTP_TRANSFER_TYPE_BINARY, 0)) {
                std::cout << "Error: " << GetLastError();
            }
        }
    }
}

但是编译器的输出是:

Info: Configuration "Debug" uses tool-chain "MinGW GCC" that is unsupported on this system, attempting to build anyway.
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -std=c++11 -o main.o "..\\main.cpp" 
C:\Users\u007\AppData\Local\Temp\ccFEaWlK.o: In function `Z4DoItRSsS_S_':
C:\projects\ftp-test\Debug/../main.cpp:10: undefined reference to `_imp__InternetOpenA@20'
C:\projects\ftp-test\Debug/../main.cpp:14: undefined reference to `_imp__InternetConnectA@32'
C:\projects\ftp-test\Debug/../main.cpp:18: undefined reference to `_imp__FtpPutFileA@20'
collect2.exe: error: ld returned 1 exit status

(我在 Eclipse 的链接器中链接到 wininet.lib 库)

(我也尝试将-lwininet 选项添加到编译器,但它什么也没做)

我使用以下软件:

  • 操作系统:Windows 10 x64
  • IDE:Eclipse Neon 3
  • 编译器:MinGW (rubenvb-4.8-stdthread) 4.8.1 20130324 (prerelease)

我看到了以下链接:1 2 3 但没有任何帮助。

感谢您的任何建议。

【问题讨论】:

  • 没有可见的 C 代码。为什么使用 C 语言标签?
  • 可能WinInet使用C但没有C++代码
  • 试试"C:\MinGW-Installation-Folder\lib\libwininet.a" 而不是"wininet.lib"

标签: c++ c eclipse wininet


【解决方案1】:

基于 g++ 编译行,它缺少要链接到 (wininet) 的库。您需要在 Eclipse 中添加该库,以便您的程序链接到它。

【讨论】:

  • 我添加了屏幕截图,您可以在其中看到 WinInet 库已添加到我的项目中,如下所述:stackoverflow.com/questions/1351712/…
  • 你确定eclipse能找到wininet吗,我看你截图里没有配置-L
  • 我什至尝试在 -l 链接器选项中指定 wininet.lib 文件的完整路径
  • 你需要把路径放在库路径部分-L(大写L),你试过吗?
  • 我刚刚注意到您收到的警告:未检测到 MINGW GCC,所以基本上。这是你的问题,eclipse 可能正在使用另一个配置 GCC 交叉编译器来编译你的程序,这就是为什么对 MINGW GCC 的任何更改都不会影响你的编译。
猜你喜欢
  • 2021-05-23
  • 1970-01-01
  • 2014-06-26
  • 2016-07-21
  • 2011-04-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
相关资源
最近更新 更多