我是新使用的WinInet,並有以下簡單的C++代碼:C++ WININET未定義的引用,即使-lwininet鏈接器標誌
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 `[email protected]'
C:\projects\ftp-test\Debug/../main.cpp:14: undefined reference to `[email protected]'
C:\projects\ftp-test\Debug/../main.cpp:18: undefined reference to `[email protected]'
collect2.exe: error: ld returned 1 exit status
(我鏈接到wininet.lib
在Eclipse的鏈接器中的庫)
(我也試着給編譯器添加-lwininet
選項,但它什麼都不做)
我使用以下軟件:
- OS:
Windows 10 x64
- IDE:
Eclipse Neon 3
- 編譯:
MinGW (rubenvb-4.8-stdthread) 4.8.1 20130324 (prerelease)
感謝您的任何建議。
沒有可見的C代碼。爲什麼使用C語言標籤? – Gerhardh
可能'WinInet'使用C但沒有C++代碼 –
嘗試''C:\ MinGW-Installation-Folder \ lib \ libwininet.a「'而不是'」wininet.lib「' –