代码之家  ›  专栏  ›  技术社区  ›  Brett

Cmake在编译期间拒绝查找dbus-0

  •  0
  • Brett  · 技术社区  · 6 年前

    嗨,我想让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/)
    

    我做错什么了??

    1 回复  |  直到 6 年前
        1
  •  0
  •   rm5248    6 年前

    在这种情况下,了解CMake的第一件事是不要使用 include_directories 包含任何带有硬编码路径的系统目录(这就是您现在所做的)。你应该做的是使用CMake FindPkgConfig

    要做到这一点,应该采取如下措施。

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