undefined reference to `shm_unlink'

1、问题描述:

在编译一个程序的时候提示这样的错误:

BLog.cpp:(.text+0x5fc): undefined reference to `shm_unlink'
DBLog.cpp:(.text+0x610): undefined reference to `shm_open'
/home/SCS/install/lib/liblog4cplus.a(timehelper.o): In function `log4cplus::helpers::Time::gettimeofday()':
/mnt/hgfs/07svn/program/SDK/log4plus/log4cplus-1.1.0/log4cplus-1.1.0/src/timehelper.cxx:102: undefined reference to `clock_gettime'
/home/SCS/install/lib/liblog4cplus.a(sleep.o): In function `unix_nanosleep':
/mnt/hgfs/07svn/program/SDK/log4plus/log4cplus-1.1.0/log4cplus-1.1.0/src/sleep.cxx:52: undefined reference to `clock_nanosleep'
collect2: ld 返回 1

2、解决办法

在前面编译的时候还没出错,只是将原来链接的liblog4cplus.so改为liblog4cplus.a,然后编译就出错了,网上搜了一下在需要加上-lrt选项,编译通过了。

3、-lrt

http://www.lehman.cuny.edu/cgi-bin/man-cgi?librt+3

rt库是运行时库,提供了一些额外的函数定义。

原文地址:https://www.cnblogs.com/lit10050528/p/4166351.html