相关疑难解决方法(0)

即使在使用-pthread -lrt进行编译时也未定义对`shm_open'的引用

我看到一个类似的问题被问到没有连贯的解决方案.在linux上使用gcc编译器,我收到消息:

/tmp/ccPNsJFZ.o: In function `main':
testChTh.c:(.text+0xbfb): undefined reference to `shm_open'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

输入 gcc -pthread -lrt -o testChTh testChTh.c命令行后.我只在代码中使用shm_open一次,即:

int shm_fd;

  /* create the shared memory segment */
  shm_fd = shm_open(name, O_RDWR, 0666);
Run Code Online (Sandbox Code Playgroud)

我有以下相关的库包括:

#include <fcntl.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
Run Code Online (Sandbox Code Playgroud)

任何见解都非常感谢!

c gcc

3
推荐指数
1
解决办法
2113
查看次数

标签 统计

c ×1

gcc ×1