sem_open problem

Green Light greenlightrh@yahoo.com.ar
Fri May 2 13:40:00 GMT 2003


This is a very simple application, i want to create a semaphore and use
it.

I'm using version:
  gcc (GCC) 3.2.3 20030222 (Red Hat Linux 3.2.2-5)
  installed by Red Hat Linux 9 installer

I'm compiling using:
  gcc ./TestProc.cpp -o ./TestProc

The return is:
In function 'main':
reference to 'sem_open' without definition
collect2: ld returned 1 exit status

This is the code:
//=================================================================

#include <semaphore.h>
#include <fcntl.h>

int main()
{
        sem_t                   *unSem;
        int                     oflag = O_CREAT;
        mode_t                  mode = 0644;
        const char              semNombre[] = "/unSem.sem1";
        unsigned int            value = 0;
        int                     sts;

        unSem = sem_open(semNombre, oflag, mode, value);
        if (unSem == (void *)-1)
        {
                printf("fallo");
        }
        else
        {
                printf("Semaforo creado");
        }

    return 0;
}

//=================================================================

Any help or sugestion for me?

Thanks!, Pablo.



More information about the Gcc-help mailing list