DBU-如何设置包括路径

dbus - how to set include paths

本文关键字:包括 路径 设置 何设置 DBU-      更新时间:2023-10-16

在我的系统dbus标头上放置在 /usr/include/dbus-1.0/dbus/中, dbus-arch-deps.h是其他位置(似乎很奇怪):我程序中的 /usr/lib/x86_64-linux-gnu/dbus-1.0/include/dbus/dbus-arch-deps.h我包括 #include<dbus-1.0/dbus/dbus.h>这样:#include<dbus/xxx.h>我可以将dbus-arch-deps.h复制到/usr/include/dbus-1.0/dbus/,但是如何修复DBUS标题中的路径?

您的系统可能已安装了PKG-Config。

g++ $(pkg-config --cflags dbus-1) main.c

pkgconfig包含一个链接器/编译器/等的数据库。使用特定库所需的标志。有关更多信息,请参见man pkg-config

首先,您需要正确安装和配置它。您应该尝试以下命令:

sudo apt-get -y install dbus libdbus-1-dev libdbus-glib-1-2 libdbus-glib-1-dev

现在,这是您应该为编译编写的Makefile:

all:
g++ dbus.cpp -I/usr/include/dbus-1.0 
    -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include 
    -I/usr/include/glib-2.0 
    -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ 
    -ldbus-1 
    -ldbus-glib-1

现在,您可以包含诸如dbus/dbus.h,dbus/dbus-glib.h等的文件。

您不需要复制文件。

使用I标志编译时,只需添加dbus所在的路径:

示例:

g++ -Wall -I /usr/include/dbus-1.0/ -o main.o

使用DBUS所在的位置(在/usr/include的标准位置中,您可以在源代码中引用以下文件:

#include <dbus/xxx.h>

同样,如果您必须针对dbus链接,则必须将该路径附加到库中的路径,包括这样的路径:

g++ -Wall -I /usr/include/dbus-1.0/ -o main.o -L <dbus library path>

dbus library path is where the libraries of dbus'Live。要弄清楚这一点,请咨询网络或搜索您的系统。

更新:

在QT-CREATOR中实现这一目标(我从未使用过),也许以下可以有所帮助:

如何在QT创建者中添加路径?