(I also tried to add -lwininet option to compiler but it does nothing) I use following"/>
  简体   繁体   中英

C++ wininet undefined reference even with -lwininet linker flag

I'm new with WinInet and have following simple C++ code:

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();
            }
        }
    }
}

But compiler's output is:

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

(I link to wininet.lib library in Eclipse's linker) 在Eclipse中添加<code> wininet.lib </ code>

(I also tried to add -lwininet option to compiler but it does nothing)

I use following software:

  • OS: Windows 10 x64
  • IDE: Eclipse Neon 3
  • Compiler: MinGW (rubenvb-4.8-stdthread) 4.8.1 20130324 (prerelease)

I saw following links: 1 2 3 but nothing there helps me.

Thanks for any suggestion.

Based on the g++ compile line it's is missing the library to link to (wininet). You need in eclipse to add that library so your program link to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM