Need to link cmake project to dl library

时间:2015-11-12 18:45:41

标签: unix cmake

I am building a shared library that uses the dlopen and dlsym system calls. When I build, I get the error

undefined reference to `dlopen`

How can I fix this? Thanks!

1 个答案:

答案 0 :(得分:10)

答案很简单:需要告诉cmake使用${CMAKE_DL_LIBS}与DL库链接。

因此,对于与使用dlopen等的库链接的任何目标,请调用:

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