2017-07-28 85 views
0

我是新使用的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的鏈接器中的庫) Adding <code>wininet.lib</code> in Eclipse

(我也試着給編譯器添加-lwininet選項,但它什麼都不做)

我使用以下軟件:

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

我看到下面的鏈接:123,但什麼也沒有幫助我。

感謝您的任何建議。

+0

沒有可見的C代碼。爲什麼使用C語言標籤? – Gerhardh

+0

可能'WinInet'使用C但沒有C++代碼 –

+0

嘗試''C:\ MinGW-Installation-Folder \ lib \ libwininet.a「'而不是'」wininet.lib「' –

回答

0

基於g ++編譯線,它缺少鏈接到的庫(wininet)。您需要在eclipse中添加該庫,以便您的程序鏈接到它。

+0

我添加了屏幕截圖, 'WinInet'庫被添加到我的項目中,如下所述:https://stackoverflow.com/questions/1351712/how-to-add-a-library-to-an-eclipse-project –

+0

你確定日食能夠找到wininet,我覺得你沒有任何-L配置截圖 – dhia

+0

我甚至試圖在-l連接器選項中指定wininet.lib文件的完整路徑 –

相關問題