I can't compile these codes with g++.
my system is linux (kernel is 2.4.0 ).
When I try to compile this program with g++ -o semw semw.cpp
It always tells me that sem_open sem_close,sem_post do not exist.But I have checked semaphore.h,I can not find any problems.
Anyone can compile these codes in system linux ,and tell me the result ?May be it is the bug of linux ?
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <semaphore.h>
#include <fcntl.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#define FILE_MODE S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH
int main(int argc,char **argv)
{
int c,flags,fd;
sem_t *sem;
int val;
if (argc!=2)
fprintf(stderr,"usage:semwait<name>");
fprintf(stderr,"usage:createSem [-e][-i initalvalue ]<name>");
//sem=sem_open(argv[1],0);
sem_open(argv[1],0);
sem_post(sem);
sem_wait(sem);
pause();
exit(0);
}
added code tags for readability --oombera