1

I'm following the GTK introduction.

My first 21 lines are:

// https://developer.gnome.org/gtk3/stable/gtk-getting-started.html#id-1.2.3.5
#include <gtk/gtk.h>

static void
print_hello (GtkWidget *widget,
                     gpointer   data)
{
      g_print ("Hello World\n");
}

static void
activate (GtkApplication* app,
          gpointer        user_data)

  GtkWidget *window;
  GtkWidget *label;
  GtkWidget *button_box;
  GtkWidget *button;

  window = gtk_application_window_new (app);

I'm building the above gtk_hello02.c file with a makefile:

# gcc gtk_hello02.c -o gtk_hello02 `pkg-config --cflags --libs gtk+-3.0`

# https://stackoverflow.com/questions/28533059/how-to-use-pkg-config-in-make
CFLAGS=-g -Wall -Wextra $(shell pkg-config --cflags gtk+-3.0)
LDFLAGS=$(shell pkg-config --libs gtk+-3.0)

CC=gcc

SOURCES=$(wildcard *.c)
EXECUTABLES=$(patsubst %.c,%,$(SOURCES))

all: $(EXECUTABLES)

clean: 
    rm $(EXECUTABLES) 

Why does it complain as follows?

gtk_hello02.c: In function ‘activate’:
gtk_hello02.c:21:3: error: expected declaration specifiers before ‘window’
   21 |   window = gtk_application_window_new (app);
      |   ^~~~~~

As far as I can see, the window is already declared as a GTK Widget. I remember I compiled that file without issues when I tried without the Makefile. I don't understand what changed now.

1 Answers1

0

That was a problem of not having a helpful IDE.

Indeed neither GVIM nor Code::Blocks give accurate errors in this situation.

Finally, after a long configuration, I've discovered that Visual Studio Code is very effective to spot the missing { instead, so it is the suggested IDE for this kind of coding support. See screenshot below:

enter image description here

  • Well the problem is not CodeBlocks. You should start learning Compiler warnings. – Michi Jun 18 '20 at 14:21
  • @Michi I have many years of experience programming with different languages and, obviously, I perfectly know how to interpret warnings or - more exactly in this case - errors of compilers. Your comment makes no sense here under this answer. –  Jun 19 '20 at 15:13
  • well, next time do not blame compilers or IDE’s for such silly mistakes. I am coding with codeblocks since 2014 and never got in such situation like you did and that’s because a programmer problem remains a programmer problem. – Michi Jun 20 '20 at 07:21