LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 02: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 02:39 AM.
 
Old 07-02-2009, 10:57 AM   #2
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

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 10:58 AM.
 
Old 07-02-2009, 10: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, 10: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



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 03:29 AM
Semaphore tzzdvd Programming 1 05-24-2005 09:23 PM
semaphore beginner_84 Programming 5 08-25-2004 06:54 PM
about semaphore dummyagain Programming 1 11-11-2003 11:09 AM
compile options for pthread with semaphore megaspaz Programming 6 10-29-2003 05:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:20 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
Open Source Consulting | Domain Registration