0
votes

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

1
The part of the command pkg-config ..... only works from the command line. You need to run that command on the command line (without the back ticks (`) and then use the output to adjust the compiler settings in codeblocks. Alternatively, you could just use a text editor to edit the code and continue to compile on the command line. The number of questions dealing with codeblocks on this site leads me to think that it is not worth the effort to learn.thurizas
You're probably using GTK+2 instead of GTK+3.S.S. Anne
@thurizas I'm not set on CodeBlocks but I have been looking for a visual IDE to run on linux (Raspbery Pi) that has a decent debugger (stepping through the code and adding watches at least). Any suggestions? (VS Code didn't work)Dani Dobre
Suggestions are difficult because they are mostly opinion-based. There are a lot of IDEs supporting debuggers, some are working out-of-the-box, others need tweaking. Did you try to find a website comparing IDEs? You might like to look at this Wikipedia page as a start.the busybee
@ Dani Dobre I've tried alot of IDE on Linux, and I always come back to what I learned with - emacs. You can run gdb from inside emacs and step through code, set break points, examine variables and memory. You mileage will definitely vary :) Just curious why can't you use gdb?thurizas

1 Answers

1
votes

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`