cmakelist.txt文件里面有这么一种语法

  1. target_link_libraries(MY_TARGET LIB1 LIB2 ... LIBN dl rt)

rt表示librt.so, librt.so是glibc中对real-time部分的支持库。所以一般含有#include头文件的代码,编译的时候需要加上-lrt

dl是libdl.so, 例如dlopen, dlclose就是这个库中函数, 也可以用${CMAKE_DL_LIBS}替换dl:

  1. target_link_libraries(MY_TARGET LIB1 LIB2 ... LIBN ${CMAKE_DL_LIBS} rt)

静态加载了这两个动态链接库!!!

CMAKE_DL_LIBS

Name of library containing dlopen and dlcose.
The name of the library that has dlopen and dlclose in it, usually -ldl on most UNIX machines.