Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-24-2008, 11:48 AM   #1
Registered: Mar 2008
Location: Arg
Distribution: Cent0S
Posts: 48

Rep: Reputation: 15
multi threads server

Hi everyone,

I am programming with the file server.c, client.c and network.c. The subject is a i am doing a simple chat tcp multi-threads. In other words, one thread per client and the following is the error:

leo@10-0-0-5:~/c2/mios/c-s-final$ make all
gcc -o server server.c -lpthread
/tmp/ccTZqeOu.o: In function `main':
server.c.text+0x3cb): undefined reference to `passage'
collect2: ld devolvió el estado de salida 1
make: *** [server] Error 1

I am using arrays of structures (defined in network.h)

One part of the code:
/*************** server.c ***********************/
while(1) {
((s_client = accept(listenfd, (struct sockaddr *) &struc_server,
&t_server)) < 0);
if (s_client == MAX_USER) {
write(s_client, "Servidor lleno. Intente más tarde.", 35);

else {

users[n_user].socket = s_client;

res = pthread_create(&(users[n_user].tid), &thread_attr, (void
*)passage, (void *)users[n_user].username);

if (res != 0) {
printf("error en pthread_create()");


/************************ end server.c *****************************/
/*********************** network.h ************************/
#ifndef NETWORK_H
#define NETWORK_H
struct struc_user {
// char username[100]; //m usado en pthread_create
// int *number_user; //m usado en el accept
int socket;
char username[100]; // usado en pthread_create
pthread_t tid;
struct struc_user users[MAX_USER];

pthread_attr_t thread_attr; //atributos del hilo

void * passage(void *arg); //fc passage que retorna un argumento
/****************** end network.h************************/

PD: passage is the fc of the threads, which there is network.c, argv 3 of pthread_create.
the fc passage is more or less:

void *passage(void *arg){
What kind or errors is 'undefined reference to `passage'' ?

Old 03-24-2008, 11:59 AM   #2
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
It is kind of hard to tell from what you've posted, but I believe this is what is going on.

It appears you have declared the passage function in network.h which I assume you've included in server.c. However, passage was probably implemented in network.c. When you build the program you either need to do something like this:

gcc -o server server.c network.c -lpthread or you need to have the network.o object built and do gcc -o server server.c network.o -lphtread. The error your getting is from the linker telling you it can't find the function passage and thus can't link the program.

Also... in the future, when posting code use the code tags so it is easier for us to read.
Old 06-19-2008, 01:22 AM   #3
LQ Newbie
Registered: Jun 2008
Posts: 1

Rep: Reputation: 0
Need help!!

Hey Irios, i am too working on the same assignment as your. Can you help me by providing codes of your program. i be grateful.Thanks.
Old 06-20-2008, 01:24 AM   #4
Wim Sturkenboom
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282

lrios might be willing to share his code, but it's the intention that you try things yourself first, else you'll never learn. If you experience problems, LQ is there to help you out.

Here you can find code for some basic client/server applications.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi-Server in C++ manolakis Programming 7 09-25-2007 02:49 AM
what should I be care of multi-threads C program naihe2010 Programming 4 11-05-2006 10:36 PM
threads web server in c maritos Programming 1 12-07-2005 02:11 AM
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 09:57 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration