cmake - Cmake 在编译期间拒绝找到 dbus-0
问题描述
嗨,我试图让 cmake 找到 dbus-1
当我尝试编译时,我不断收到此错误
-- Checking for module 'dbus-1'
-- No package 'dbus-1' found
我试过这个命令
pkg-config --cflags dbus-glib-1
我得到输出
-I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
我编辑了 CMakeLists.txt 并添加了
include_directories(/usr/include/dbus-1.0/)
我究竟做错了什么??
解决方案
在这种情况下,首先要了解 CMake 是不要使用include_directories
包含硬编码路径的任何系统目录(这就是您现在正在做的事情)。您应该做的是使用 CMakeFindPkgConfig
模块,该模块将调用 pkg-config 并为您获取这些包含目录。
为此,应该使用以下类似的方法。
include( FindPkgConfig )
pkg_check_modules( dbus REQUIRED dbus-1 )
# Add the include directories to our target executable/shared object.
# In this case, our target is called 'executable' and must have been
# created by a previous call to either 'add_executable' or 'add_library'
target_include_directories( executable PUBLIC ${dbus_INCLUDE_DIRECTORIES} )
推荐阅读
- arrays - 如何在matlab中计算一些随机生成的矩阵和给定数组之间的距离
- python - 为什么python中有elif?
- javascript - Forge 查看器事件文档
- selenium - Selenium JavascriptExecutor document.evaluate 'XPathResult':结果类型不是数字
- google-cloud-platform - Google Data Studio - 刷新嵌入式网站上的数据
- kubernetes - Kong背后的Keycloak和奇怪的重定向
- javascript - 替换html标签之间的字符串,多次出现问题
- scala - Semigroup typeclass (Either) 与略有改变的组合
- r - 删除数值向量列表中仅包含零的向量
- android - 为什么我得到这个“找不到 com.google.firebase:firebase-core:16.1.0。” 一直出错?