I am trying to learn dbus and compilation/linking of programs on Linux. I am fairly new to building and linking applications from scratch. To this end, I am creating a simple client+server applications on Ubuntu which communicate over gdbus. I am using gdbus-codegen tool to generate .c and .h files for the dbus interfaces. I have created a sample xml description file named dbus_interface.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
"http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
<node>
<interface name="org.hello.world">
<method name="get_magic_number">
<arg type="i" name="magic_number" direction="out"/>
</method>
</interface>
</node>
and I am generating the code using the following command:
gdbus-codegen --generate-c-code generated_code dbus_interface.xml
which generates the generated_code.c and generated_code.h files. I have included the generated_code.h header file inside my client application, which I am trying to compile with gcc using the following command:
gcc -Wall -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include client.c generated_code.c -o client
However, I get the following error:
generated_code.c:17:12: fatal error: gio/gunixfdlist.h: No such file or directory
17 | # include <gio/gunixfdlist.h>
| ^~~~~~~~~~~~~~~~~~~
compilation terminated.
Why is this header file not present on my system? I have the gio directory in /usr/include/glib-2.0/gio, and it contains a bunch of header files - but not gunixfdlist.h.
As a side note:
- I am not using pkg-config in the build command on purpose in order to better understand what pkg-config expands to during the compilation
- I guess that I will have to provide the actual library locations to the linker as well to my build command, but I wanted to solve the issue of not resolving includes properly first
The header file is in
/usr/include/gio-unix-2.0/gio
. As noted in the documentation:So you should be using pkg-config in your project configuration, and make sure that
gio-unix-2.0
is included in the invocation that gets your compile flags.