需要将cmake项目链接到dl库 [英] Need to link cmake project to dl library

查看:73
本文介绍了需要将cmake项目链接到dl库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用dlopen和dlsym系统调用的共享库。
编译时出现错误

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`

我该如何解决?谢谢!

推荐答案

答案很简单:需要告知cmake使用 $ {CMAKE_DL_LIBS}

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

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

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})

这篇关于需要将cmake项目链接到dl库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆