问题
On my system dbus headers are placed in /usr/include/dbus-1.0/dbus/
and dbus-arch-deps.h
is other location (what seems to be strange): /usr/lib/x86_64-linux-gnu/dbus-1.0/include/dbus/dbus-arch-deps.h
In my program I include #include<dbus-1.0/dbus/dbus.h>
but in every header file which include others path looks like this: #include<dbus/xxx.h>
I can copy dbus-arch-deps.h
to /usr/include/dbus-1.0/dbus/
but how to fix paths in dbus headers ?
回答1:
Your system likely has pkg-config installed.
g++ $(pkg-config --cflags dbus-1) main.c
Pkgconfig contains a database of linker/compiler/etc. flags that are required to use specific libraries. See man pkg-config
for more info.
回答2:
You don't need to copy files.
Simply add the path of where dbus
is located to your include path when compiling using the I
flag:
example:
g++ -Wall -I /usr/include/dbus-1.0/ -o main.o
By using the location of where dbus is located (in the standard location of /usr/include
, you can reference the files like the following in your source code:
#include <dbus/xxx.h>
Similarly, if you have to link against dbus
you'll have to append that path to the Libraries inclusion path like so:
g++ -Wall -I /usr/include/dbus-1.0/ -o main.o -L <dbus library path>
Where dbus library path is where the libraries of
dbus` live. To figure this out, consult the web, or search your system.
UPDATE:
To achieve that in Qt-Creator (which I've never used), perhaps the following can help:
How to add include path in Qt Creator?
回答3:
First of all you need to install and configure it properly. You should try this command :
sudo apt-get -y install dbus libdbus-1-dev libdbus-glib-1-2 libdbus-glib-1-dev
Now, here is the Makefile that you should write for compiling :
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
Now, you may include files like dbus/dbus.h, dbus/dbus-glib.h, etc.
来源:https://stackoverflow.com/questions/21602607/dbus-how-to-set-include-paths