【问题标题】:dbus - how to set include pathsdbus - 如何设置包含路径
【发布时间】:2014-03-03 09:08:24
【问题描述】:
在我的系统上,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 标头中的路径?
【问题讨论】:
标签:
c++
ubuntu-12.04
dbus
【解决方案1】:
您的系统可能安装了 pkg-config。
g++ $(pkg-config --cflags dbus-1) main.c
Pkgconfig 包含链接器/编译器/等数据库。使用特定库所需的标志。请参阅man pkg-config 了解更多信息。
【解决方案2】:
首先,您需要正确安装和配置它。
你应该试试这个命令:
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 等文件。
【解决方案3】:
您不需要复制文件。
使用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 ofdbus` 住的地方。要弄清楚这一点,请查阅网络或搜索您的系统。
更新:
要在 Qt-Creator(我从未使用过)中实现这一点,也许以下内容会有所帮助:
How to add include path in Qt Creator?