Translate-C error on 0.16.0

I’m upgrading to 0.16.0, but I’m running into trouble with zig translate-c and GTK. In c.h, I have:

#include <gtk/gtk.h>

The following succeeds on 0.15.2, but fails on 0.16.0:

zig translate-c -lc -I/usr/include/gtk-4.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/graphene-1.0 -I/usr/lib64/graphene-1.0/include c.h

with the following errors:

error: translation failure
/usr/include/gtk-4.0/gdk/version/gdkversionmacros.h:19:2: error: \"Only <gdk/gdk.h> can be included directly.\"
#error "Only <gdk/gdk.h> can be included directly."
 ^
/usr/include/glib-2.0/glib/gutils.h:327:1: error: unknown type name 'pragma'
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
^
/usr/include/glib-2.0/glib/gmacros.h:757:39: note: expanded from here
  _Pragma ("GCC diagnostic push")
                                      ^
<scratch space>:83:2: note: expanded from here
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 ^
/usr/include/glib-2.0/glib/gutils.h:327:1: error: expected ';', found 'an identifier'
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
^
/usr/include/glib-2.0/glib/gmacros.h:757:39: note: expanded from here
  _Pragma ("GCC diagnostic push")
                                      ^
<scratch space>:83:13: note: expanded from here
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
            ^
/usr/include/glib-2.0/glib/gutils.h:327:1: error: unknown type name 'diagnostic'
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
^
/usr/include/glib-2.0/glib/gmacros.h:757:39: note: expanded from here
  _Pragma ("GCC diagnostic push")
                                      ^
<scratch space>:83:13: note: expanded from here
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

// continues for 200,000 lines

I realise that this is probably system-dependent, and I apologise for not knowing much about C/C compilers (I can’t provide a smaller, more explicit example). The installed GTK and glib versions are 4.20.3 and 2.84.4, respectively if that helps.

With the upgrade, they started using arocc for the translation. I also ran into this issue. I’m trying to work a fix through arocc and into translate-c. Once those land, you can import translate c as a dependancy and it should “just work”.

Unfortunately, this means that you will currently be unable to use Zig 0.16 for translating those files.

1 Like