【发布时间】:2012-07-16 08:50:43
【问题描述】:
鉴于此代码:
#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);
}
我从 eclipse undefined reference to sem_open 得到。
我已经检查了这个post,因为这个问题与我的非常相似,但不明白我的错误在哪里,
您能否解释一下我需要在哪里修复它/添加另一个编译命令(如果确实如此)?
非常感谢
【问题讨论】:
-
请仔细阅读该问题的第二个答案。你没有做它说你应该做的事情。
-
我不知道eclipse是怎么工作的,所以这里有个问题:什么时候报错?它是在您输入 sem_open 时显示在编辑器中,还是仅在/编译时显示?你是怎么编译的?
-
@ArjunShankar:只有当我编译它时。
标签: c linux ubuntu pipe shared-memory