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

时间:2019-01-07 02:40:07

标签: cmake dbus

您好,我想让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 个答案:

答案 0 :(得分:0)

The first thing to know about CMake in this situation is don't use the include_directories to include any system directories with a hard-coded path(which is what you are doing now). What you should do instead is use the CMake FindPkgConfig module which will call pkg-config and get those include directories for you.

To do this, something like the following should work.

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