SCTP Discussions

Text archives Help


[SCTP-Discussion] "Undefined reference..." when compiling programs


Chronological Thread 
  • From: "Oon Heok Kee" <oonheokkee78 AT hotmail.com>
  • To: discussion AT sctp.de
  • Subject: [SCTP-Discussion] "Undefined reference..." when compiling programs
  • Date: Wed Aug 21 07:52:00 2002
  • List-id: SCTP Discussions <discussion.sctp.de>

Hi,

I'm running on RH Linux 7.3 (kernel version 2.4.18-3), and using sctplib-1.0.0-pre19 and socketapi-1.0.0.

I tried writing a small test program, just to have the client PC send a string to the server and the server echoing back. However, when I try to compile the program with "gcc -o test_server test_server.c -lsctp -lglib", these are the error messages that I get:

/tmp/cciFks8A.o: In function `HandleTCPClient':
/tmp/cciFks8A.o(.text+0x4b): undefined reference to `ext_recv'
/tmp/cciFks8A.o(.text+0xcb): undefined reference to `ext_send'
/tmp/cciFks8A.o(.text+0xfe): undefined reference to `ext_recv'
/tmp/cciFks8A.o(.text+0x13f): undefined reference to `ext_close'
/tmp/cciFks8A.o: In function `main':
/tmp/cciFks8A.o(.text+0x1c4): undefined reference to `ext_socket'
/tmp/cciFks8A.o(.text+0x258): undefined reference to `ext_bind'
/tmp/cciFks8A.o(.text+0x28e): undefined reference to `ext_listen'
/tmp/cciFks8A.o(.text+0x2d2): undefined reference to `ext_accept'
collect2: ld returned 1 exit status

These are the header files that I've included in the program. And if it helps, I've attached the code as below (within the lines of '*'). I've also checked that ext_socket.h and sctp.h has a copy at the following locations:

/usr/local/include/ext_socket.h
/usr/src/socketapi-1.0.0/socketapi/ext_socket.h
/usr/local/include/sctp.h
/usr/src/sctplib-1.0.0-pre19/sctplib/sctp/sctp.h

Sorry for the dumb question... and thanks a million!!



Oon, Heok Kee

************************************************************************
/* SCTP echo-server */

#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), bind(), and connect() */
#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */
#include <stdlib.h> /* for atoi() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */
#include <sys/types.h>
#include <sys/time.h>
#include <ext_socket.h>
#include <net/route.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sctp.h>


#define MAXPENDING 5 /* Maximum outstanding connection requests */
#define RCVBUFSIZE 512 /* Size of receive buffer */


void DieWithError(char *errorMessage)
{
perror(errorMessage);
exit(1);
}


void HandleTCPClient(int clntSocket)
{
char echoBuffer[RCVBUFSIZE]; /* Buffer for echo string */
int recvMsgSize; /* Size of received message */

printf("Receiving message from client...\n\n");
/* Receive message from client */
if ((recvMsgSize = ext_recv(clntSocket, echoBuffer, RCVBUFSIZE, 0)) < 0)
DieWithError("recv() failed");

echoBuffer[recvMsgSize] = '\0';

printf("Message received: %s\n\n", echoBuffer);

printf("Echoing back to client...\n\n");
/* Send received string and receive again until end of transmission */
while (recvMsgSize > 0) /* 0 indicates end of transmission */
{
/* Echo message back to client */
if (ext_send(clntSocket, echoBuffer, recvMsgSize, 0) != recvMsgSize)
DieWithError("send() failed");

/* See if there is more data to receive */
if ((recvMsgSize = ext_recv(clntSocket, echoBuffer, RCVBUFSIZE,
0)) < 0)
DieWithError("recv() failed");
}

/*free(&echoBuffer);*/
printf("Closing connection... ");
ext_close(clntSocket); /* Close client socket */
printf("Connection closed.\n\n");
}


int main(int argc, char *argv[])
{
int servSock; /* Socket descriptor for server */
int clntSock; /* Socket descriptor for client */
struct sockaddr_in echoServAddr; /* Local address */
struct sockaddr_in echoClntAddr; /* Client address */
unsigned short echoServPort; /* Server port */
unsigned int clntLen; /* Length of client address */

if (argc != 2) /* Test for correct number of arguments */
{
fprintf(stderr, "Usage: %s <Server Port>\n", argv[0]);

exit(1);
}

echoServPort = atoi(argv[1]); /* First arg: local port */

printf("\nCreating socket... ");
/* Create socket for incoming connections */
if ((servSock = ext_socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP))<0)
DieWithError("socket() failed");
printf("Socket created.\n\n");

/* Construct local address structure */
/* Zero out structure */
memset(&echoServAddr, 0, sizeof(echoServAddr));

echoServAddr.sin_family = AF_INET;/* Internet addr. family */

/* Any incoming interface */
echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY);

echoServAddr.sin_port = htons(echoServPort); /* Local port */

printf("Binding to address... ");
/* Bind to the local address */
if (ext_bind(servSock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
DieWithError("bind() failed");
printf("Address bounded.\n\n");

/* Mark the socket so it will listen for incoming conn. */
if (ext_listen(servSock, MAXPENDING) < 0)
DieWithError("listen() failed");

for (;;) /* Run forever */
{
/* Set the size of the in-out parameter */
clntLen = sizeof(echoClntAddr);

printf("Waiting for connection... ");
/* Wait for a client to connect */
if ((clntSock = ext_accept(servSock, (struct sockaddr *) &echoClntAddr, &clntLen)) < 0)
DieWithError("accept() failed");
printf("Connected.\n\n");

/* clntSock is connected to a client! */
printf("Handling client %s\n\n",
inet_ntoa(echoClntAddr.sin_addr));

HandleTCPClient(clntSock);
}
}
************************************************************************



_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com




  • [SCTP-Discussion] "Undefined reference..." when compiling programs, Oon Heok Kee, 08/21/2002

Archive powered by MHonArc 2.6.19+.

Top of page