我想从我的C ++项目中启动/停止systemd服务。因此,我喜欢使用提供的systemd lib和头文件。我正在使用cmake生成makefile。我正在尝试通过cmake获取systemd
pkg_check_modules(SDBUS REQUIRED systemd)
实际上是作为
message(STATUS "FOUND" ${SDBUS_FOUND})
返回1。
但是,cmake创建的所有其他必要的变量就像
message(STATUS "LIBS" ${SDBUS_LIBRARIES})
message(STATUS "LIB_DIRS" ${SDBUS_LIBRARY_DIRS})
message(STATUS "LDFLAGS" ${SDBUS_LDFLAGS})
message(STATUS "LDFLAGS_OTHER" ${SDBUS_LDFLAGS_OTHER})
message(STATUS "INCLUDE DIRS" ${SDBUS_INCLUDE_DIRS})
message(STATUS "CFLAGS" ${SDBUS_CFLAGS})
message(STATUS "CFLAGS_OTHER" ${SDBUS_CFLAGS_OTHER})
是空的。编译项目时会导致链接器错误。确实在打电话时
pkg-config --libs systemd
它也是空的。任何人都知道如何解决这个问题以及为什么所有这些信息都不适用于systemd?
您可以看到systemd没有提供它们
%pkg-config systemd --print-variables
binfmtdir
catalogdir
containeruidbasemax
containeruidbasemin
dynamicuidmax
dynamicuidmin
modulesloaddir
pcfiledir
prefix
sysctldir
systemdshutdowndir
systemdsleepdir
systemdsystemconfdir
systemdsystemgeneratordir
systemdsystempresetdir
systemdsystemunitdir
systemdsystemunitpath
systemduserconfdir
systemdusergeneratordir
systemduserpresetdir
systemduserunitdir
systemduserunitpath
systemdutildir
systemgidmax
systemuidmax
sysusersdir
tmpfilesdir
所以FindPkgConfig模块在这里没用......
你应该使用libsystemd-dev代替
那么你会有
%pkg-config libsystemd --print-variables
exec_prefix
includedir
libdir
pcfiledir
prefix
%pkg-config libsystemd --libs
-lsystemd