LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-01-2009, 03:14 AM   #1
e_deb_2002
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Rep: Reputation: 0
Question Cannot compile with semaphore.h


Hi guys,

I am a C# dev (as far as my job goes). recently I started trying out C. i preferred linux to be the better platform for C codes.

Problem is: I have never done anything on compiling C codes more than standard "cc xyz.c -o xyz.exe"

Now that I have used #include<semaphore.h> in my code, it not compiling any more. cc -c is working though.
the command executed looks like: cc main.c -o synchronize.exe
I do not remember the exact error message, but it's something like
definition for sem_init not found, or undefined sem_init referred to.... something in the same line.

I am not exactly sure of what exactly to do here.

I am using slackware version 10.1. [default installation(full)]

Thanks in advance.

Last edited by e_deb_2002; 07-01-2009 at 03:39 AM.
 
Old 07-02-2009, 11:57 AM   #2
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 297

Rep: Reputation: 62
What platform are you on? What compiler are you using? I notice you are trying to compile a .exe.

Can you show us your source code? Just including this header should not cause your source code not to compile.

Last edited by fpmurphy; 07-02-2009 at 11:58 AM.
 
Old 07-02-2009, 11:59 AM   #3
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
You need to link to the POSIX thread library, so add -pthread to gcc options. When you're facing this kind of problem, read the manual: "man sem_init" to display the sem_init online manual... "man" is another good reason for using an UNIX system to do C development...
 
Old 07-07-2009, 11:35 AM   #4
e_deb_2002
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Hi,

Thanks for the info.
Including -lpthread did it.

As for the man pages, I was actually trying out with the info pages. But I guess man pages are better than info's.

Thanks again, as I solved the compilation issue, and am into a runtime issue now.
Anyways, the semaphores are working fine now...
 
  


Reply


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
Kernel Compile problem (FC 3, 2.6.11.6 -> 2.6.13.3, semaphore.c) U4ea Linux - Software 1 10-07-2005 04:29 AM
Semaphore tzzdvd Programming 1 05-24-2005 10:23 PM
semaphore beginner_84 Programming 5 08-25-2004 07:54 PM
about semaphore dummyagain Programming 1 11-11-2003 12:09 PM
compile options for pthread with semaphore megaspaz Programming 6 10-29-2003 06:05 PM


All times are GMT -5. The time now is 09:48 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration