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!
答案 0 :(得分:10)
答案很简单:需要告诉cmake使用${CMAKE_DL_LIBS}
与DL库链接。
因此,对于与使用dlopen等的库链接的任何目标,请调用:
target_link_libraries(MY_TARGET LIB1 LIB2 ... LIBN ${CMAKE_DL_LIBS})