在mac下编译一个程序的时候遇到错误

ld: library not found for -lrt

librt.so主要是glibc对real-time部分的支持.所以一般含有#include<time.h>头文件的代码,编译的时候需要加上-lrt

makefile里面有使用-lrt的命令

网上有很多文章意思是mac的lib和include库需要引用下:https://blog.csdn.net/u010487504/article/details/9004706

但是即使引用了也是没有用的。因为:https://issues.apache.org/jira/browse/THRIFT-3121

可以使用类似程序判断是否支持lrt

lrt:=$(shell echo "int main() {}"|gcc -x c - -lrt 2>&1)
ifeq ($(lrt),)
  lrtlibs:=-lrt
else
  lrtlibs:=
endif


LIBS:=                    \
    -lpthread $(lrtlibs)

相关文章:

  • 2022-12-23
  • 2021-08-03
  • 2021-04-10
  • 2022-12-23
  • 2021-06-26
  • 2021-09-18
  • 2021-04-24
  • 2021-05-19
猜你喜欢
  • 2022-02-11
  • 2021-11-27
  • 2022-12-23
  • 2021-11-20
  • 2021-07-22
  • 2021-08-17
  • 2021-08-20
相关资源
相似解决方案