sem_open不与Ubuntu的工作:未定义的参考`sem_open“ [英] sem_open doesn't work with Ubuntu : undefined reference to `sem_open'
问题描述
有鉴于此code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <semaphore.h>
#include <pthread.h>
#define BUF_SIZE 256
int main()
{
key_t key;
char *virtualaddr;
sem_t *get, *put;
int shmid;
const char* messageOne = "Hello world , I'm child number 1\n";
const char* messageTwo = "Hello world , I'm child number 2\n";
char buf[BUF_SIZE];
key = ftok("anyfile",'R');
shmid = shmget(key,1024,0644|IPC_CREAT);
...
...
shmctl (shmid, IPC_RMID, NULL);
exit(EXIT_SUCCESS);
}
我从月食未定义的引用到sem_open
。
我检查这个<一个href=\"http://stackoverflow.com/questions/4916881/sem-open-error-undefined-reference-to-sem-open-on-linux-ubuntu-10-10\">post因为这个问题是非常相似的矿,但如果是我的失误并没有完全理解,
I've check with this post since this question is very similar to mine , but didn't understand exactly where is my mistake ,
能否请你解释一下我在哪里需要修复/添加另一个编译命令(如果这是事实确实如此)?
Can you please explain where do I need to fix it / add another compilation command (if this is indeed the case) ?
大部分AP preciated
Much appreciated
推荐答案
您编译时需要包括 -lpthread
。这是由链接器使用,您对二进制链接库。
You need to include -lpthread
when compiling. This is used by the linker, to link your binary against the library.
的其他答案已经涵盖如何做到这一点的命令行上。的
为此在Eclipse中,您需要按照指示这里:
To do this in Eclipse, you need to follow the directions here:
在项目属性,进入:C / C ++编译 - >设置。然后
工具设置,选择库,连接器下。您可以添加
你的项目库有(不带-l)。另外,在低
部分,您可以添加到检索库自定义路径
In the project properties, go to : C/C++ Build --> Settings. Then "Tool Settings", select "Libraries" under "Linker". You can add all your project libraries there (without the "-l"). Also in the lower part, you can add custom path to search libraries
这篇关于sem_open不与Ubuntu的工作:未定义的参考`sem_open“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!