2

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:

  1. 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
  2. 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
Moon_Raven
  • 309
  • 2
  • 12
  • Learn to use [GNU make](https://www.gnu.org/software/make/). You might have missing packages, and these are specific to your Linux distribution. I recommend using [Debian](http://debian.org/) or [Ubuntu](http://ubuntu.org/) but there are many others. See https://linuxfromscratch.org/ ; read documentation of [GCC](http://gcc.gnu.org/) and of [GDB](https://www.gnu.org/software/gdb/) and compile with all warnings and debug info `gcc -Wall -Wextra -g` – Basile Starynkevitch Sep 01 '20 at 18:46
  • Hello! I am actually using a makefile to issue the compile command that I listed. I just extracted the exact command which is giving me problems. Thanks for the provided links - I will check them out! As for the GDB and debug info - I fear it will not help since I can't even get through the preprocessing stage, let alone compile and debug the program. – Moon_Raven Sep 01 '20 at 19:06

1 Answers1

4

The header file is in /usr/include/gio-unix-2.0/gio. As noted in the documentation:

Note that <gio/gunixfdlist.h> belongs to the UNIX-specific GIO interfaces, thus you have to use the gio-unix-2.0.pc pkg-config file when using it.

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.

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • Thanks a lot - I solved my issue by using your answer. In CMake I used ``pkg_check_modules(GIO-UNIX gio-unix-2.0 REQUIRED)`` ``include_directories(${GIO-UNIX_INCLUDE_DIRS})`` - Don't forget to set target link libraries: ``target_link_libraries(${PROJECT_NAME} ${GIO-UNIX_LDFLAGS})`` – bem22 Mar 10 '21 at 16:09