Dani Dobre
Dani Dobre

Reputation: 29

GTK app compiles with gcc, but does not compile in codeblocks

Looking to implement a drawing canvas in C/C++ and, after failing to make code from the internet work, I came across this sample code which does exactly what I need. The code compiles with the terminal command provided by Martin:

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

In Codeblocks, I've started a new GTK+ Project, added the sample code in it and I get

error: unkown type name 'GtkApplication'

Please advise how to set up CodeBlocks. I've tried tinkering with the Compiler Options in CodeBlocks without any luck.

Follow-up:

  1. I checked which packages I have installed and it seems I have both GTK2 and GTK3. enter image description here

  2. I've pasted the output of the "command flags" ...

pkg-config --cflags --libs gtk+-3.0

in CodeBlocks -> Project -> Build Options -> Other compiler options. The previous errors are gone, but new errors are raised:

undefined reference to 'gtk_widget_get_allocated_width'

undefined reference to 'gtk_widget_get_allocated_height'

undefined reference to 'gtk_application_window_new'

undefined reference to 'gtk_application_get_type'

undefined reference to 'gtk_window_set_application'

undefined reference to 'gtk_box_new'

undefined reference to 'gtk_application_new'

The motivation behind all this is to use a debugger (I am not able to work with text-based gdb).

Many thanks, Dani

Upvotes: 0

Views: 502

Answers (1)

Dani Dobre
Dani Dobre

Reputation: 29

Found the solution:

In CodeBlocks, Project -> Build Options ->Compiler settings -> Other compiler options, add

`pkg-config --cflags gtk+-3.0`

In Project -> Build Options ->Linker settings -> Other linker options, add

`pkg-config --libs gtk+-3.0`

Upvotes: 2

Related Questions