sem_open() error: "undefined reference to sem_open()" on linux (Ubuntu 10.10)

Posted by Robin on Stack Overflow See other posts from Stack Overflow or by Robin
Published on 2011-02-06T23:17:35Z Indexed on 2011/02/06 23:25 UTC
Read the original article Hit count: 376

Filed under:
|
|

So I am getting the error: "undefined reference to sem_open()" even though I have include the semaphore.h header. The same thing is happening for all my pthread function calls (mutex, pthread_create, etc). Any thoughts? I am using the following command to compile:

g++ '/home/robin/Desktop/main.cpp' -o '/home/robin/Desktop/main.out'

#include <iostream>
using namespace std;
#include <pthread.h>
#include <semaphore.h>
#include <fcntl.h>

const char *serverControl = "/serverControl";
sem_t* semID;

int main ( int argc, char *argv[] )
{
    //create semaphore used to control servers
    semID = sem_open(serverControl,O_CREAT,O_RDWR,0);
    return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about linux