Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to link cmake project to dl library

Tags:

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!

like image 708
Jacko Avatar asked Nov 12 '15 18:11

Jacko


1 Answers

The answer turns out to be quite simple: cmake needs to be told to link with the DL libs, using ${CMAKE_DL_LIBS} .

So, for any target that links with a library that uses dlopen, etc, invoke:

target_link_libraries(MY_TARGET LIB1 LIB2 ... LIBN ${CMAKE_DL_LIBS})
like image 168
Jacko Avatar answered Oct 04 '22 17:10

Jacko