Unknown type name

please am having some compile error from my code
the is my out put from my compile

Emptying app dir '/home/goldman/.var/app/org.gnome.Builder/cache/gnome-builder/projects/text-viewer/flatpak/staging/x86_64-main'
error: org.gnome.Sdk/x86_64/45 not installed
error: org.gnome.Sdk/x86_64/45 not installed
error: org.gnome.Platform/x86_64/45 not installed
Downloading sources
Stopping at module text-viewer
Starting build of com.example.TextViewer
Stopping at module text-viewer
Everything cached, checking out from cache
Pruning cache
[1/2] Compiling C object src/text-viewer.p/text-viewer-window.c.o
FAILED: src/text-viewer.p/text-viewer-window.c.o 
ccache cc -Isrc/text-viewer.p -Isrc -I../../../../../../../../../Projects/text-viewer/src -I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/graphene-1.0 -I/usr/lib/x86_64-linux-gnu/graphene-1.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/fribidi -I/usr/include/webp -I/usr/include/libpng16 -I/usr/include/pixman-1 -I/usr/include/libadwaita-1 -I/usr/include/appstream -I/home/goldman/.var/app/org.gnome.Builder/cache/gnome-builder/projects/text-viewer/builds/com.example.TextViewer.json-flatpak-org.gnome.Platform-45-x86_64-main -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wcast-align -Wdeclaration-after-statement -Werror=address -Werror=array-bounds -Werror=empty-body -Werror=implicit -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Werror=init-self -Werror=int-conversion -Werror=int-to-pointer-cast -Werror=main -Werror=misleading-indentation -Werror=missing-braces -Werror=missing-include-dirs -Werror=nonnull -Werror=overflow -Werror=pointer-arith -Werror=pointer-to-int-cast -Werror=redundant-decls -Werror=return-type -Werror=sequence-point -Werror=shadow -Werror=strict-prototypes -Werror=trigraphs -Werror=undef -Werror=write-strings -Wformat-nonliteral -Wignored-qualifiers -Wimplicit-function-declaration -Wlogical-op -Wmissing-declarations -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wno-cast-function-type -Wno-dangling-pointer -Wno-missing-field-initializers -Wno-sign-compare -Wno-unused-parameter -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wuninitialized -Wunused -fno-strict-aliasing -Werror=format-security -Werror=format=2 -fstack-protector-strong -mfpmath=sse -msse -msse2 -pthread -mfpmath=sse -msse -msse2 -MD -MQ src/text-viewer.p/text-viewer-window.c.o -MF src/text-viewer.p/text-viewer-window.c.o.d -o src/text-viewer.p/text-viewer-window.c.o -c ../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c
In file included from /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h:9,
                 from /usr/include/glib-2.0/glib/gtypes.h:34,
                 from /usr/include/glib-2.0/glib/galloca.h:34,
                 from /usr/include/glib-2.0/glib.h:32,
                 from /usr/include/gtk-4.0/gtk/css/gtkcss.h:29,
                 from /usr/include/gtk-4.0/gtk/gtk.h:29,
                 from /usr/include/libadwaita-1/adwaita.h:9,
                 from ../../../../../../../../../Projects/text-viewer/src/text-viewer-window.h:23,
                 from ../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:23:
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c: In function ‘open_file_complete’:
/usr/include/glib-2.0/glib/gmacros.h:1347:43: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
 1347 | #define _GLIB_CLEANUP(func)               __attribute__((cleanup(func)))
      |                                           ^~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gmacros.h:1385:20: note: in expansion of macro ‘_GLIB_CLEANUP’
 1385 | #define g_autofree _GLIB_CLEANUP(g_autoptr_cleanup_generic_gfree)
      |                    ^~~~~~~~~~~~~
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:63:3: note: in expansion of macro ‘g_autofree’
   63 |   g_autofree char *display_name = NULL;
      |   ^~~~~~~~~~
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:79:60: error: format ‘%s’ expects a matching ‘char *’ argument [-Werror=format=]
   79 |     g_printerr ("Unable to print to load the contents of “%s”: the file is not encoded with UTF-8\n" );
      |                                                           ~^
      |                                                            |
      |                                                            char *
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:85:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   85 |   GtkTextBuffer *buffer = gtk_text_view_get_buffer (self->main_text_view);
      |   ^~~~~~~~~~~~~
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:90:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   90 |   GtkTextIter start;
      |   ^~~~~~~~~~~
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c: In function ‘on_open_response’:
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:103:3: error: unknown type name ‘TextViewer’
  103 |   TextViewer *self = user_data;
      |   ^~~~~~~~~~
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:103:15: warning: unused variable ‘self’ [-Wunused-variable]
  103 |   TextViewer *self = user_data;
      |               ^~~~
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:102:18: warning: unused variable ‘dialog’ [-Wunused-variable]
  102 |   GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
      |                  ^~~~~~
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c: In function ‘text_viewer_window_init’:
/usr/include/glib-2.0/glib/gmacros.h:1347:43: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
 1347 | #define _GLIB_CLEANUP(func)               __attribute__((cleanup(func)))
      |                                           ^~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gmacros.h:1380:29: note: in expansion of macro ‘_GLIB_CLEANUP’
 1380 | #define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName)
      |                             ^~~~~~~~~~~~~
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:117:9: note: in expansion of macro ‘g_autoptr’
  117 |         g_autoptr (GSimpleAction) open_action = g_simple_action_new("open", NULL);
      |         ^~~~~~~~~
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c: At top level:
../../../../../../../../../Projects/text-viewer/src/text-viewer-window.c:97:13: warning: ‘open_file’ defined but not used [-Wunused-function]
   97 | static void open_file(TextViewerWindow *self, GFile *file){
      |             ^~~~~~~~~
cc1: some warnings being treated as errors
ninja: build stopped: subcommand failed.

this is my code below

static void
on_open_response (GObject      *source,
                  GAsyncResult *result,
                  gpointer      user_data)
{
  GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
  TextViewer *self = user_data;

  g_autoptr (GFile) file =
    gtk_file_dialog_open_finish (dialog, result, NULL);

  // If the user selected a file, open it
  if (file != NULL)
    open_file (self, file);
}

It seems you have -pedantic or -stdc=c89 in your compiler flags. Don’t do that.

Use -stdc=gnu99 or -stdc=gnu11, and never use -pedantic with GLib code.

which do i need to make this change?

Find out where your compiler flags are set, and change them.

It seems you are using GNOME Builder and you’re trying to build an example from the GNOME Developer documentation—this kind of details is important, and you should always provide it.

The actual error is here:

   79 |     g_printerr ("Unable to print to load the contents of “%s”: the file is not encoded with UTF-8\n" );
      |                                                           ~^
      |                                                            |
      |                                                            char *

Remove the %s from the format string.

please how do i correct it? do you mean i should use %c?

No, I said: remove the %s from the format string, not replace it.

There’s no argument for the modifier.

thank you sir this explains it.

fixed, lastly please is there a pdf book for the gnome builder tutorials?

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