未定义的引用'的shm_open“,已经在这里添加-lrt标志 [英] undefined reference 'shm_open', already add -lrt flag here
本文介绍了未定义的引用'的shm_open“,已经在这里添加-lrt标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是有一个系统崩溃,并重新安装的Ubuntu 11.10,和我的code产生这种奇怪的错误。
I just have a system crash and reinstall Ubuntu 11.10, and my code produces this strange error.
我写了一个简单的code样品测试的问题所在:
I wrote a simple code sample to test where the problem is:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
int main (void) {
int i;
i = shm_open ("/tmp/shared", O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); printf ("shm_open rc = %d\n", i);
shm_unlink ("/tmp/shared");
return (0);
}
和编译命令是
的gcc -lrt -o test.c的测试
该错误是:
/tmp/ccxVIUiP.o: In function `main':
test.c:(.text+0x21): undefined reference to `shm_open'
test.c:(.text+0x46): undefined reference to `shm_unlink'
collect2: ld returned 1 exit status
我已经添加-lrt lib下,为何仍不能编译?
I have already added -lrt lib, why does it still not compile?
推荐答案
末库:
的gcc -o test.c的测试-lrt
gcc test.c -o test -lrt
链接选项:
-llibrary
-l library
Search the library named library when linking.
(The second alternative with the library as a separate argument
is only for POSIX compliance and is not recommended.)
It makes a difference where in the command you write this option;
the linker searches and processes libraries and object files in the
order they are specified.
Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but
before bar.o. If bar.o refers to functions in `z', those functions
may not be loaded.
这篇关于未定义的引用'的shm_open“,已经在这里添加-lrt标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文