473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

undefined reference

5
Hello everybody
im creating a srever program for my work
that can communicate with the client using udp protocol.

i get couple errors and i do not know hat those error mean and what is the problem with by code.
Need Help

The code:

#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <time.h>
#include <netdb.h>
#include <sys/signal.h>
#include <string.h> //for strln()
#include <sys/types.h>
#include <fcntl.h>


#define EOB "Client:$$"
#define KB_size 80
#define MAX_CLIENT 100
int ClientNo = 0;

////////////////////////////////////////////
int openService (int NoClients)
{int sock;
int intPort;
char host[80];
char KB_buff[KB_size];

sock = sockTCP_create();
printf("Enter port: ");
fgets(KB_buff, KB_size, stdin);
intPort = atoi(KB_buff);
sock_bind(sock, intPort);
sock_listen(sock, NoClients);
gethostname(host,80);
printf("ITserver at %s [ %d]\n",
host,intPort);
return (sock);
}
////////////////////////////////////////////
int getClient(MSsock)
{char *cli_name;
struct sockaddr_in *client_EP;

int sock;
char *msg =
"Type any string or EOB to quit\n";
time_t con_time;

sock = sock_accept(MSsock, &client_EP);
if (sock == 0) IO_error (0, "accept");
else {
time(&con_time);
writeMessage(sock, msg);
ClientNo += 1;
cli_name = (char *)getNameByEP (*client_EP);
printf ("Client %d (%s-%d)\n", ClientNo,
cli_name, client_EP->sin_port);
printf (" -->connect at %s\n",
asctime (localtime (&con_time)));
}
return (sock);
}
////////////////////////////////////////////
int DST_SingEcho (int sock,char *msg)
// Get a message at sock, if message <> EOB
// echo back, else B or "" then quit;
{
int nc;
int quit = 0;

nc = readMessage (sock,msg);
quit = (strncmp(msg,EOB, 9) == 0);
if(quit==0)
return 0;
return nc;
}

////////////////////////////////////////////
int main()
{
int MS_socket,MS_UDP,
CS_socket[MAX_CLIENT],CS_udp[MAX_CLIENT],i,iRet,iMaxSock=0;
struct sockaddr_in servaddr, cliaddr[MAX_CLIENT];
time_t cli_time;
fd_set fdRead;
struct timeval tv = {1,1};
char sRecvMsg[1024];

memset((char*)CS_socket,0,sizeof(int)*MAX_CLIENT);
memset((char*)CS_udp,0,sizeof(int)*MAX_CLIENT);
MS_socket = openService (0);
MS_UDP = open_UDP();
while (1)
{
FD_ZERO(&fdRead);

FD_SET(MS_socket,&fdRead);
iMaxSock = MS_socket;

for(i=0;i<MAX_CLIENT;i++)
{
if(CS_socket[i] >0)
{
fcntl(CS_socket[i], F_SETFL, O_NONBLOCK);
iMaxSock = (iMaxSock > CS_socket[i])?iMaxSock:CS_socket[i];
FD_SET(CS_socket[i],&fdRead);
}
}
tv.tv_sec =1;
tv.tv_usec = 0;
iRet = select( iMaxSock +1,&fdRead,NULL,NULL,&tv);
if(iRet==0)
continue;
else if(iRet >0)
{
if(FD_ISSET(MS_socket,&fdRead))
{
CS_socket[i] = getClient(MS_socket,cliaddr[i]);
}

for(i=0;i<MAX_CLIENT;i++)
{
if((CS_socket[i] > 0) && (FD_ISSET(CS_socket[i],&fdRead)))
{
//recv
memset(sRecvMsg,0,sizeof(sRecvMsg));
if(DST_SingEcho(CS_socket[i],sRecvMsg) ==0)
{
close(CS_socket[i]);
CS_socket[i]=0;
}
//multicast
for(i=0;i<MAX_CLIENT;i++)
{
if(CS_socket[i] > 0)
{
sendtoDST (cliaddr[i],CS_udp,sRecvMsg);
}
}
}
}
}

}
return 1;
}





the error code that im getting is:

gcc -o server_it server_it.c DST_sock.o
/tmp/cckBqZJJ.o(.text+0x281): In function `main':
server_it.c: undefined reference to `open_UDP'
collect2: ld returned 1 exit status
Sep 7 '07 #1
2 1367
gpraghuram
1,275 Expert 1GB
Hi,
I think the error u get is because u havent included the UDP library while compiling.
The syntax is gcc *.c -l<udplibrary> -o <>
Note:Plese add code tags before posting.

Thanks
Raghuram
Sep 7 '07 #2
JosAH
11,448 Expert 8TB
i get couple errors and i do not know hat those error mean and what is the problem with by code.

the error code that im getting is:

gcc -o server_it server_it.c DST_sock.o
/tmp/cckBqZJJ.o(.text+0x281): In function `main':
server_it.c: undefined reference to `open_UDP'
collect2: ld returned 1 exit status
Your program tries to call the function open_UDP() but the linker found that there
isn't any. The linker (collect2) complains about it ('ld' is just the frontend of the
linker called by the compiler). You have to supply it a library that contains that function.

kind regards,

Jos

edit: may you and this guy can work together.
Sep 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on...
13
by: david | last post by:
Hi, I have some problems to link a simple hello world program using g++ (version 3.2.3 or 3.3) and dinkumware 402. //hallo world... #include <iostream> main () { std::cout << "bla" <<...
1
by: Codemutant | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** I just cannot find what is undefined in this code.
1
by: Foolster41 | last post by:
I'm rather new to C++ programing. I'm using the dev-C++ program on a windows XP OS. I'm trying to compile the code for a multi user dungeon (MUD) called circle-mud. When I compile I get the...
1
by: Dom | last post by:
I'm new to c++. Just started learning it 24 hours ago. Am running into a compile problem. Please, no one waste the effort telling me to google it. I've been researching it for quite a while with no...
1
by: Andre Janssen | last post by:
Hi.... I tried to compile the following src with this command: "g++ -Wall -o bla alsaswitch.cpp". The src is an example src of xosd package. #include <xosd.h> int main (int argc, char...
3
by: Michael Sgier | last post by:
Hi i get thousands of messages like below. How shall i resolve that? Thanks Mcihael Release/src/Utility/RawImage.o: In function `CMaskImage::CMaskImage(int, int, char const*)':...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
3
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE...
2
by: zqiang320 | last post by:
Hello: I execute make ,then get error: $ make Making all in libsbml/src make: Entering directory `/home/internet/mydoc/test_pj/libsbml/src' ........ /bin/sh ./libtool --tag=CC --mode=link...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.