Ok I'm back to having problems in Dev cpp with my socket programming code.
I'm almost 100% certain it's to do with the code structure:
Code:
class sockID{
private:
string sockName, address;
struct sockaddr_in cSock;
unsigned short int *port;
public:
//the GET functions
string getSockName() {return sockName; }
string getSockAddress () {return address;}
int getPort () {return (int) port;}
//constructors
sockID(string s_address, unsigned short int s_Port);
sockID(string s_Name, string s_address, unsigned short int s_Port);
};
// Class constructors
sockID::sockID(string s_Name, string s_address, unsigned short int s_Port) {
port = &cSock.sin_port;
sockName = s_Name;
cSock.sin_family = AF_INET;
cSock.sin_port = s_Port; // short, network byte order MAY NOT WORK
cSock.sin_addr.s_addr = inet_addr( s_address.c_str() );
//inet_aton(s_address.c_str(), &(cSock.sin_addr)); <== not valid in windows
memset(cSock.sin_zero, '\0', sizeof cSock.sin_zero);
and then
Code:
int main() {
//WSADATA wsaData; // if this doesn't work
WSAData wsaData; // then try this instead
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
fprintf(stderr, "WSAStartup failed.\n");
exit(1);
}
rest of main..
everything's in one file at the moment because this is a skeleton I'm building so I'd like to get it working before I tidy everything up into files.
Basically I'm still getting the same: [Linker error] undefined reference to `WSAStartup@8' and [Linker error] undefined reference to `inet_addr@4' errors in dev cpp
when I compile the file alone I get no errors whatsoever but when I compile the project it throws up these errors.
My best guess is that maybe it's because I'm using those functions before the windows sockets initialisation routine.