I borrowed some code from a snippet I found here at D.I.C. to try wrapping my head around Winsock again, but I keep getting linker errors. After looking over the errors I'm convinced it can't find any of the functions in "winsock.h".
most of the build log:
CODE
------ Build started: Project: winsockTest1, Configuration: Debug Win32 ------
Compiling...
main.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol _WSACleanup@0
main.obj : error LNK2001: unresolved external symbol "int __cdecl DoWinsock(char const *,int)" (?DoWinsock@@YAHPBDH@Z)
main.obj : error LNK2001: unresolved external symbol _WSAStartup@8
C:\Documents an...\winsockTest1\Debug\winsockTest1.exe : fatal error LNK1120: 3 unresolved externals
the program (main.cpp)
CODE
#include <winsock.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
extern int DoWinsock(const char* pcHost, int nPort);
const int kDefaultServerPort = 4242; //default port to connect to on server
int main(int argc, char* argv[])
{
//test for enough arguments
if (argc < 2)
{
cerr<<"usage: "<<argv[0]<<" <server-address> [server-port]"<<endl<<endl;
cerr<<"\tIf you don't pass server-port, it defaults to "<<kDefaultServerPort<<"."<<endl;
return 1;
}
//get host and (optionally) port from command line
const char* pcHost = argv[1];
int nPort = kDefaultServerPort;
if (argc >= 3)
{
nPort = atoi(argv[2]);
}
//sanity check
int nNumArgsIgnored = (argc - 3);
if (nNumArgsIgnored > 0)
{
cerr<<nNumArgsIgnored<<" extra argument"<<(nNumArgsIgnored == 1 ? "" : "s")<<" ignored."<<endl;
}
//start Winsock
WSAData wsaData;
int nCode;
if ((nCode = WSAStartup(MAKEWORD(1, 1), &wsaData)) != 0)
{
cerr<<"WSAStartup() returned error code "<<nCode<<"."<<endl;
return 255;
}
//call main example routine
int retVal = DoWinsock(pcHost, nPort);
//shut Winsock down
WSACleanup();
return retVal;
}