g++ compiles a program g++ Shm.c-o SHM,
With the Shm_open (), Shm_unlink () function, the following error has occurred in compiling:
`del_resource()‘`shm_unlink‘`main‘`shm_open‘collect2: error: ld returned 1 exit status
Later through the Shm_open () document, impressively found the following content:
Enter the man Shm_open carriage return in the terminal:
SYNOPSIS #include <sys/mman.h> #include <sys/stat.h> /* For mode constants */ #include <fcntl.h> /* For O_* constants */ int shm_open(constcharint oflag, mode_t mode); int shm_unlink(constchar *name); Link with -lrt.
Link WITH-LRT indicates that the compiler should add-LRT.
So the correct compile command should be:
g++ Shm.c-lrt-o SHM
I think similar to this compilation error, a good way is to look at the man document and find out if you need to show links to other libraries.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
gcc/g++ undefined reference to function () Problem resolution