Problem with WSAStartup, error LNK2001

C

coldwind2010

I try to programme a simply FTP client.
I use 3 files: FTPconnect.cpp,FTPconnect.h,FTP.cpp.
I use Visual Studio 2008
compiles are all right;but when I built:
there are 2 error :
FTPconnect.obj : error LNK2001: unresolved external symbol
__imp__WSAStartup@8
fatal error LNK1120: 1 unresolved externals

what is the problem;
code as fellow:

FTPconnect.h:

#include<string>
using namespace std;
class FTPconnect
{
private:
string state;
int IPadr;
public:
void open(string hostadr);
void dir(string dirname);
void get_in_dir(string dirname);
void get_file(string filename,string localadr);
void upload_file(string filename);
};

FTPconnect.cpp:

#include "FTPconnect.h"
#include <iostream>
#include <Winsock2.h>
using namespace std;
void FTPconnect::eek:pen(string hostadr)
{
if (hostadr == "")
{
cout<<"Please enter the FTP sites which you want login:";
cin>>hostadr;
}
//$B=i;O2=(Bsocket

WSADATA wsaData;
int err;
err = WSAStartup( 0x0101, &wsaData );
if ( err != 0 ) cout<<"Error";
}

FTP.cpp:

#include "FTPconnect.h"
#include <iostream>
using namespace std;
void hint(string &command,string &information);
int main(void)
{
string command,information;
while(1)
{
hint(command,information);
cout<<"command="<<command<<"information="<<information<<endl;
if (command == "quit" || command == "bye")
{
cout<<"GoodBye"<<endl;
break;
}
command = "";
information = "";
}
return 0;
}
void hint(string &command,string &information)
{
string input;
int local;
cout<<"FTP>";
getline(cin,input);
local = input.find(" ");
if (local == string::npos)
command = input;
else
{
command = input.substr(0,local);
information = input.substr(local+1);
cout<<"Has space"<<endl;
}
}
 
J

Junchen WANG

I try to programme a simply FTP client.
I use 3 files: FTPconnect.cpp,FTPconnect.h,FTP.cpp.
I use Visual Studio 2008
compiles are all right;but when I built:
there are 2 error :
FTPconnect.obj : error LNK2001: unresolved external symbol
__imp__WSAStartup@8
fatal error LNK1120: 1 unresolved externals

what is the problem;
code as fellow:

FTPconnect.h:

#include<string>
using namespace std;
class FTPconnect
{
private:
string state;
int IPadr;
public:
void open(string hostadr);
void dir(string dirname);
void get_in_dir(string dirname);
void get_file(string filename,string localadr);
void upload_file(string filename);

};

FTPconnect.cpp:

#include "FTPconnect.h"
#include <iostream>
#include <Winsock2.h>
using namespace std;
void FTPconnect::eek:pen(string hostadr)
{
if (hostadr == "")
{
cout<<"Please enter the FTP sites which you want login:";
cin>>hostadr;
}
//³õʼ»¯socket

WSADATA wsaData;
int err;
err = WSAStartup( 0x0101, &wsaData );
if ( err != 0 ) cout<<"Error";

}

FTP.cpp:

#include "FTPconnect.h"
#include <iostream>
using namespace std;
void hint(string &command,string &information);
int main(void)
{
string command,information;
while(1)
{
hint(command,information);
cout<<"command="<<command<<"information="<<information<<endl;
if (command == "quit" || command == "bye")
{
cout<<"GoodBye"<<endl;
break;
}
command = "";
information = "";
}
return 0;}

void hint(string &command,string &information)
{
string input;
int local;
cout<<"FTP>";
getline(cin,input);
local = input.find(" ");
if (local == string::npos)
command = input;
else
{
command = input.substr(0,local);
information = input.substr(local+1);
cout<<"Has space"<<endl;
}



}- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

When compiling your application with WINSOCK2.H, you should link with
WS2_32.LIB library.

Best Regards,
Junchen
 
C

coldwind2010

When compiling your application with WINSOCK2.H, you should link with
WS2_32.LIB library.

Best Regards,
Junchen- Hide quoted text -

- Show quoted text -

Thank you very much!
Follow your help,
I add this "#pragma comment(lib,"ws2_32.lib");"
And solve this problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top