質問

#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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top