Feb 9, 2012 at 10:42pm UTC
Hello everyone,
I'm fairly new to c++ programming and I have a networking project to do. Below is the code of my .cpp file along with .h files. I've been stuck since last few days on three LNK 2019 errors and one LNK 1120 errors. I am assuming LNK 1120 is occuring due to previous LNK 2019 errors.
/* webclient.c */
//#include<iostream>
#include <stdlib.h>
#include <stdio.h>
#include "cnaiapi.h"
#include "cnaiapi_win32.h"
#define BUFFSIZE 256
//using namespace std;
/*-----------------------------------------------------------------------
*
* Program: webclient
* Purpose: fetch page from webserver and dump to stdout with headers
* Usage: webclient <compname> <path> [appnum]
* Note: Appnum is optional. If not specified the standard www appnum
* (80) is used.
*
*-----------------------------------------------------------------------
*/
int main(int argc, char *argv[])
{
computer comp;
appnum app;
connection conn;
char buff[BUFFSIZE];
int len;
if (argc < 3 || argc > 4) {
(void) fprintf(stderr, "%s%s%s", "usage: ", argv[0],
" <compane> <path> [appnum]\n");
exit(1);
}
/* convert arguments to binary computer and appnum */
comp = cname_to_comp(argv[1]);
if (comp == -1)
exit(1);
if (argc == 4)
app = (appnum) atoi(argv[3]);
else
if ((app = appname_to_appnum("www")) == -1)
exit(1);
/* contact the web server */
conn = make_contact(comp, app);
if (conn < 0)
exit(1);
/* send an HTTP/1.0 request to the webserver */
len = sprintf(buff, "GET %s HTTP/1.0\r\n\r\n", argv[2]);
(void) send(conn, buff, len, 0);
/* dump all data received from the server to stdout */
while((len = recv(conn, buff, BUFFSIZE, 0)) > 0)
(void) write(STDOUT_FILENO, buff, len);
return 0;
}
------------------------------------------------------------------
/* cnaiapi.h */
#ifndef _CNAIAPI_H_
#define _CNAIAPI_H_
#if defined(LINUX) || defined(SOLARIS)
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <pthread.h>
#include <unistd.h>
#endif /* defined(LINUX) || defined(SOLARIS) */
#if defined(_WIN32)
#include <winsock2.h>
#include <cnaiapi_win32.h>
#endif /* defined(_WIN32) */
#include <sys/types.h>
typedef short appnum;
typedef long computer;
typedef int connection;
struct port2sock {
short port;
int sock;
};
#define P2S_SIZE 64 /* number of entries in port to socket map table */
#define LISTEN_Q_LEN 5
appnum appname_to_appnum(char *appname);
computer cname_to_comp(char *cname);
connection await_contact(appnum a);
connection make_contact(computer c, appnum a);
int send_eof(connection c);
void cnaiapi_init(void);
#if defined(LINUX) || defined(SOLARIS)
extern pthread_mutex_t await_contact_mutex, cname_mutex, appname_mutex;
#elif defined(_WIN32)
extern HANDLE await_contact_mutex, cname_mutex, appname_mutex;
#endif
#endif /* !defined(_CNAIAPI_H_) */
--------------------------------------------------------------------------
/* cnaiapi_win32.h */
#include <io.h>
#define read _read
#define write _write
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
--------------------------------
I've also tried editing linker option: Linker - Input - Additional dependencies - ws2_32.lib
Plzzzzzzzzzzzzzzzzzzzzzzzz Help........
Sunny
Feb 9, 2012 at 10:45pm UTC
We need to see the whole error message to know which library or object file you aren't linking against properly.