Jump to content
  • Advertisement
Sign in to follow this  
Knight52

Basic Client/Server: unresolved externals

This topic is 2542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just copied from a tutorial. All I've changed was include the stdafx.h in first line, but I've got 11 unresolved externals errors. What happened?

I started the project as Win32 Console application.


#include "stdafx.h"
#include <winsock2.h>
#include <windows.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
DWORD WINAPI SocketHandler(void*);
int main(int argv, char** argc){
//The port you want the server to listen on
int host_port= 1101;
//Initialize socket support WINDOWS ONLY!
unsigned short wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 || ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ))
{
fprintf(stderr, "Could not find useable sock dll %d\n",WSAGetLastError());
goto FINISH;
}
//Initialize sockets and set any options
int hsock;
int * p_int ;
hsock = socket(AF_INET, SOCK_STREAM, 0);
if(hsock == -1)
{
printf("Error initializing socket %d\n",WSAGetLastError());
goto FINISH;
}

p_int = (int*)malloc(sizeof(int));
*p_int = 1;
if( (setsockopt(hsock, SOL_SOCKET, SO_REUSEADDR, (char*)p_int, sizeof(int)) == -1 )||
(setsockopt(hsock, SOL_SOCKET, SO_KEEPALIVE, (char*)p_int, sizeof(int)) == -1 ) )
{
printf("Error setting options %d\n", WSAGetLastError());
free(p_int);
goto FINISH;
}
free(p_int);
//Bind and listen
struct sockaddr_in my_addr;
my_addr.sin_family = AF_INET ;
my_addr.sin_port = htons(host_port);

memset(&(my_addr.sin_zero), 0, 8);
my_addr.sin_addr.s_addr = INADDR_ANY ;

if( bind( hsock, (struct sockaddr*)&my_addr, sizeof(my_addr)) == -1 )
{
fprintf(stderr,"Error binding to socket, make sure nothing else is listening on this port %d\n",WSAGetLastError());
goto FINISH;
}
if(listen( hsock, 10) == -1 )
{
fprintf(stderr, "Error listening %d\n",WSAGetLastError());
goto FINISH;
}

//Now lets to the server stuff
int* csock;
sockaddr_in sadr;
int addr_size = sizeof(SOCKADDR);

while(true)
{
printf("waiting for a connection\n");
csock = (int*)malloc(sizeof(int));

if((*csock = accept( hsock, (SOCKADDR*)&sadr, &addr_size))!= INVALID_SOCKET ){
printf("Received connection from %s",inet_ntoa(sadr.sin_addr));
CreateThread(0,0,&SocketHandler, (void*)csock , 0,0);
}
else{
fprintf(stderr, "Error accepting %d\n",WSAGetLastError());
}
}
FINISH:
;
}
DWORD WINAPI SocketHandler(void* lp)
{
int *csock = (int*)lp;
char buffer[1024];
int buffer_len = 1024;
int bytecount;
memset(buffer, 0, buffer_len);
if((bytecount = recv(*csock, buffer, buffer_len, 0))==SOCKET_ERROR)
{
fprintf(stderr, "Error receiving data %d\n", WSAGetLastError());
goto FINISH;
}
printf("Received bytes %d\nReceived string \"%s\"\n", bytecount, buffer);
strcat_s(buffer, " SERVER ECHO");
if((bytecount = send(*csock, buffer, strlen(buffer), 0))==SOCKET_ERROR)
{
fprintf(stderr, "Error sending data %d\n", WSAGetLastError());
goto FINISH;
}

printf("Sent bytes %d\n", bytecount);

FINISH:
free(csock);
return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
We need to know errors...



1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__inet_ntoa@4 referenced in function _main
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__accept@12 referenced in function _main
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__listen@8 referenced in function _main
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__bind@12 referenced in function _main
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__htons@4 referenced in function _main
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__setsockopt@20 referenced in function _main
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__socket@12 referenced in function _main
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__WSAGetLastError@0 referenced in function _main
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _main
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__send@16 referenced in function "unsigned long __stdcall SocketHandler(void *)" (?SocketHandler@@YGKPAX@Z)
1>ServerConsole.obj : error LNK2019: unresolved external symbol __imp__recv@16 referenced in function "unsigned long __stdcall SocketHandler(void *)" (?SocketHandler@@YGKPAX@Z)
1>F:\Users\Knight\Documents\Visual Studio 2010\Projects\ServerConsole\Debug\ServerConsole.exe : fatal error LNK1120: 11 unresolved externals[/quote]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!