LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 12-22-2002, 07:37 AM   #1
nickthegreek82
LQ Newbie
 
Registered: Dec 2002
Location: Greece
Distribution: Mandrake Linux 9.1 RULEZ
Posts: 13

Rep: Reputation: 0
Problem With Semaphores in Linux


I have written this small program but i take a strange error from gcc compiler

#include <semaphore.h>
extern int errno;
main()
{
sem_t sp;
int retval;
retval=sem_init(&sp,0,2);
if(retval!=0)
{
perror("Couldn't initialize.");
exit(3);
}
}
When i try to complile it,gcc says :
/tmp/ccwEPiIp.o: In function `main':
/tmp/ccwEPiIp.o(.text+0x1c): undefined reference to `sem_init'
collect2: ld returned 1 exit status

Any ideas ? thanks
 
Old 12-22-2002, 07:40 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
how are you using gcc? you'ev probably not set to link the semaphore linbrary, whatever it's actually called. add -lsem or whatever it should be.
 
Old 12-22-2002, 08:41 AM   #3
cybercop12us
Member
 
Registered: Aug 2001
Posts: 60

Rep: Reputation: 15
i think u need to do like what chris says gcc -o eg -lrt eg.c

see the man page synopsis for lib to link with gcc
 
Old 12-22-2002, 09:24 AM   #4
nickthegreek82
LQ Newbie
 
Registered: Dec 2002
Location: Greece
Distribution: Mandrake Linux 9.1 RULEZ
Posts: 13

Original Poster
Rep: Reputation: 0
thanks for your help but now the problem i have is to intentify which library i need to link ... but i think oi will find it out soon
 
Old 12-23-2002, 08:02 AM   #5
cybercop12us
Member
 
Registered: Aug 2001
Posts: 60

Rep: Reputation: 15
see the man page for sem_init . in that under synopsis you should be having something like cc -lrt or -lsem something...
 
Old 12-28-2002, 11:10 AM   #6
nickthegreek82
LQ Newbie
 
Registered: Dec 2002
Location: Greece
Distribution: Mandrake Linux 9.1 RULEZ
Posts: 13

Original Poster
Rep: Reputation: 0
I still haven't found the library i need , i searched to all man and info pages and there is nothing...If anyone knows the right lib ,please post a message... Thanks
 
Old 12-30-2002, 10:03 PM   #7
Morpheus
Member
 
Registered: Dec 2002
Posts: 49

Rep: Reputation: 15
hi...
do u really wanna use these semaphores ??
there are another set of semaphores defined in the systemv

u could get info on them by the man pages on semop,semctl,semget

these r preety simple and have been used
 
  


Reply



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
questions on semaphores feetyouwell Programming 3 10-03-2004 09:55 PM
What is Semaphores? imsajjadali Red Hat 3 04-23-2004 01:26 AM
Linux 2.6 Real time semaphores? illuminatedwax Linux - General 0 04-14-2004 04:26 AM
Semaphores help mojozoox Programming 1 01-07-2004 08:41 AM
semaphores charles_sjc Linux - Software 2 12-06-2003 12:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:58 PM.

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