我看到一个类似的问题被问到没有连贯的解决方案.在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)
任何见解都非常感谢!