【问题标题】:Cmake refuses to find dbus-0 during compileCmake 在编译期间拒绝找到 dbus-0
【发布时间】:2019-01-07 02:40:06
【问题描述】:

您好,我正在尝试让 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/)

我做错了什么??

【问题讨论】:

  • 在 shell 中,您运行 pkg-config 以获取包 dbus-glib-1。但是错误信息是关于dbus-1 包的。

标签: cmake dbus


【解决方案1】:

在这种情况下,首先要了解 CMake 是不要使用 include_directories 包含任何具有硬编码路径的系统目录(这就是您现在正在做的事情)。您应该改为使用 CMake FindPkgConfig 模块,该模块将调用 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} )

【讨论】:

    猜你喜欢
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    相关资源
    最近更新 更多