简体   繁体   中英

Wininet giving linker errors I'm using devc++

#include <iostream>
#include <windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet")
#include <pshpack4.h>
#include <poppack.h>
using namespace std;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{
HINTERNET hInternet;
HINTERNET hFtpSession;
hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
hFtpSession = InternetConnect(hInternet, "ftp.drivehq.com",INTERNET_DEFAULT_FTP_PORT, "usr" ,"pass", INTERNET_SERVICE_FTP, 0, 0);
FtpPutFile(hFtpSession, "log.txt", "mylog.txt", FTP_TRANSFER_TYPE_BINARY, 0);

InternetCloseHandle(hFtpSession);
InternetCloseHandle(hInternet);

return 0;
}
[Linker error] undefined reference to `InternetOpenA@20' 
[Linker error] undefined reference to `InternetConnectA@32' 
[Linker error] undefined reference to `FtpPutFileA@20' 
[Linker error] undefined reference to `InternetCloseHandle@4' 
[Linker error] undefined reference to `InternetCloseHandle@4' 
ld returned 1 exit status 
C:\Users\Wade\Desktop\test\command builder\Makefile.win [Build Error]  [command.exe] Error 1

What's wrong with my code here it keeps giving me linker errors?

I had many errors like this on my first C++ program. It is a problem with linking against the WinINet library. If you are using MinGW add "-lwininet" (without quotes) to the additional commandling arguments and it should be fixed. I don't know what to to do if you use VC++. Also, make sure the location of the WinINet library is in the linker's search paths. One other note: The INTERNET_PER_CONN_* variables, along with a few others, do not exist in MinGW's WinInet, and I have not found a solution to fixing it yet.

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