sem_open()错误:“未定义对sem_open()的引用” on linux(Ubuntu 10.10) [英] sem_open() error: "undefined reference to sem_open()" on linux (Ubuntu 10.10)
本文介绍了sem_open()错误:“未定义对sem_open()的引用” on linux(Ubuntu 10.10)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我得到的错误:未定义的引用sem_open()即使我已经包括semaphore.h头。同样的事情发生在我所有的pthread函数调用(mutex,pthread_create等)。有什么想法吗?我使用以下命令进行编译:
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 '
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;
}
推荐答案
,使用 -lpthread
选项。
这篇关于sem_open()错误:“未定义对sem_open()的引用” on linux(Ubuntu 10.10)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文