Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   sem.h Problem (http://www.go4expert.com/forums/semh-problem-t20903/)

icu222much 8Feb2010 04:46

sem.h Problem
 
I am trying to program with semaphores and was told that I should use sem.h. When I compile, I get the error: "sys/sem.h: No such file or directory". How can I fix my problem?

Code:

#include <stdio.h>
#include <sys/sem.h>


int main() {
    printf("I am alive \n");
    getchar();
    return 0;
}


shabbir 8Feb2010 07:56

Re: sem.h Problem
 
Remove that line

icu222much 8Feb2010 10:17

Re: sem.h Problem
 
Removing that line would get rid of the error, but I still would like to use semaphores.

shabbir 8Feb2010 10:33

Re: sem.h Problem
 
Quote:

Originally Posted by icu222much (Post 63971)
Removing that line would get rid of the error, but I still would like to use semaphores.

But if that file isn't there in your system and so having that file is not the way out.

icu222much 8Feb2010 11:13

Re: sem.h Problem
 
How would I get that file onto my computer?

I found sem.h, downloaded it, and placed it in the directory (C:\Program Files (x86)\CodeBlocks\MinGW\include). When I ran my program, the compiler said there were lots of problems with sem.h. After doing some research, I found out that I can't just add sem.h as this is just a 'pointer' file which is suppose to point to the actual code behind this function. I am trying to find how to get the actual code on my computer.

Sorry, I am very new to programming in C.

shabbir 8Feb2010 16:41

Re: sem.h Problem
 
If you are new try your hands on basics as that file may be in some external package which you may need to install

xpi0t0s 9Feb2010 12:24

Re: sem.h Problem
 
Semaphores are done differently on Windows than on Unix/Linux. sem.h and the related libraries are Unix. If you're programming Windows then you'll need to know about MSDN. Here's a demo program for semaphores on MSDN:

http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx


All times are GMT +5.5. The time now is 10:57.