Unable to generate GObject introspection data for library

Hi!

I’m the author and maintainer of libgpiod. I’m building a D-Bus daemon for managing GPIOs in linux and basing the work on GLib bindings to libgpiod I created and which @pwithnall has been already helping me with on the linux-gpio mailing list (thanks!).

I’m stuck on generating the introspection data for the library and have been unable to move it forward. Here is the relevant Makefile.

Here’s the relevant portion of it:

if HAVE_INTROSPECTION

INTROSPECTION_GIRS = Gpiodglib-1.0.gir

girdir = $(INTROSPECTION_GIRDIR)
gir_DATA = Gpiodglib-1.0.gir

typelibsdir = $(INTROSPECTION_TYPELIBDIR)
typelibs_DATA = Gpiodglib-1.0.typelib

Gpiodglib_1_0_gir_SCANNERFLAGS = \
	--c-include="gpiod-glib.h" \
	--warn-all \
	--namespace Gpiodglib \
	--identifier-prefix Gpiodglib \
	--symbol-prefix gpiodglib

Gpiodglib_1_0_gir_CFLAGS = $(libgpiod_glib_la_CFLAGS)

Gpiodglib-1.0.gir: libgpiod-glib.la
Gpiodglib_1_0_gir_INCLUDES = Gio-2.0
Gpiodglib_1_0_gir_LIBS = libgpiod-glib.la
Gpiodglib_1_0_gir_FILES = $(libgpiod_glib_la_SOURCES)
Gpiodglib_1_0_gir_EXPORT_PACKAGES = gpiod-glib

include $(INTROSPECTION_MAKEFILE)

endif

The generated .gir file looks like this:

<?xml version="1.0"?>
<!-- This file was automatically generated from C sources - DO NOT EDIT!
To affect the contents of this file, edit the original C definitions,
and/or use gtk-doc annotations.  -->
<repository version="1.2"
            xmlns="http://www.gtk.org/introspection/core/1.0"
            xmlns:c="http://www.gtk.org/introspection/c/1.0"
            xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
  <include name="Gio" version="2.0"/>
  <package name="gpiod-glib"/>
  <c:include name="gpiod-glib.h"/>
  <namespace name="Gpiodglib"
             version="1.0"
             shared-library="libgpiod-glib.so.1"
             c:identifier-prefixes="Gpiodglib"
             c:symbol-prefixes="gpiodglib">
  </namespace>
</repository>

And the following warning is emitted by g-ir-scanner:

<unknown>:: Error: Gpiodglib: Namespace is empty; likely causes are:
* Not including .h files to be scanned
* Broken --identifier-prefix

I’ve based my work on some existing examples that do work - namely UDisks2 which also uses autotools. Any hints as to what is wrong with my example?

To reproduce:

git clone https://github.com/brgl/libgpiod-private -b b4/dbus libgpiod
cd libgpiod
./autogen --enable-bindings-glib
make

The individual .h files (chip.h, line.h, etc) need to be passed in to the command as well, not just the .c files. So I think you could move the HEADERS variable up to bindings/glib/Makefile.am and then do:

Gpiodglib_1_0_gir_FILES = $(otherinclude_HEADERS) $(libgpiod_glib_la_SOURCES)

Ah, right, this seems to be the culprit.

Just to clarify, the introspection data is generated from a combination of two things, namely:

  1. C declarations
  2. doc blocks

The introspection scanner builds an AST of declarations, and then pairs them with their corresponding doc blocks (if any). This means you need to pass to it both the headers with all the public API declarations, and the source files that contain the doc blocks. The doc blocks contain the annotations necessary to describe the semantics of an API, like ownership transfer, direction, and types.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.