RomoBoom
Posts: 45
Joined: Sat Sep 01, 2018 12:07 am

i am trying to make a small window appear, with nothing in it, but it just isn't working.

Sun May 05, 2019 1:58 pm

i am trying to make a small window appear, with nothing in it, but it just isn't working
The code is from a book called
AN INTRODUCTION TO
---------C & GUI-------------
----PROGRAMMING-----
By: Simon Long
Code:

Code: Select all

#include <gkt/gkt.h>

int main (int argc,char *argv[])
{
  gkt_init (&argc, &argv);
  GtkWidget *win = gkt_window_new (GKT_WINDOW_TOPLEVEL);
  gkt_widget_show (win);
  gkt_main ();
  return 0;
}
(in geany)
and this happens
(i ran it through the terminal)
error.png
picture of error
error.png (116.95 KiB) Viewed 1541 times
if you see what is wrong, please tell me, so that i can fix it :D :D :)

User avatar
buja
Posts: 506
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: Is this wrong?

Sun May 05, 2019 2:01 pm

Just a guess: wrong spelling: gkt => should be gtk, try:

Code: Select all

#include <gtk/gtk.h>
Edit: now that I try it myself I see that you made the same typo everywhere :lol:
Edit 2: it might be a good idea to download the PDF of the book and copy & paste the example programs instead of typing them, saves a few errors.
Last edited by buja on Mon May 06, 2019 1:00 pm, edited 1 time in total.

User avatar
B.Goode
Posts: 8881
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Is this wrong?

Sun May 05, 2019 3:37 pm

This is a cut'n paste of the PDF download -

Code: Select all

#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
 gtk_init (&argc, &argv);
 GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 gtk_widget_show (win);
 gtk_main ();
 return 0;
}

So unless something went badly wrong when the paper book was printed, it seems your code is not what is in the book.

cmrincon
Posts: 40
Joined: Thu May 24, 2018 7:39 pm

Re: Is this wrong?

Mon May 06, 2019 10:27 am

From that same guide:

Code: Select all

First we need to make sure that the relevant GTK libraries are installed. To do this, type
sudo apt-get install libgtk2.0-dev into a terminal window and answer yes to any
prompts – this installs the developer libraries for GTK 2.

User avatar
B.Goode
Posts: 8881
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Is this wrong?

Mon May 06, 2019 10:38 am

cmrincon wrote:
Mon May 06, 2019 10:27 am
From that same guide:

Code: Select all

First we need to make sure that the relevant GTK libraries are installed. To do this, type
sudo apt-get install libgtk2.0-dev into a terminal window and answer yes to any
prompts – this installs the developer libraries for GTK 2.


Obviously correct in itself.


But as already stated, it won't help with compilation of code that contains:

Code: Select all

#include <gkt/gkt.h>

RomoBoom
Posts: 45
Joined: Sat Sep 01, 2018 12:07 am

Re: Is this wrong?

Sun May 12, 2019 5:22 pm

buja wrote:
Sun May 05, 2019 2:01 pm
Just a guess: wrong spelling: gkt => should be gtk, try:

Code: Select all

#include <gtk/gtk.h>
Edit: now that I try it myself I see that you made the same typo everywhere :lol:
Edit 2: it might be a good idea to download the PDF of the book and copy & paste the example programs instead of typing them, saves a few errors.
its from a book, so no copy paste

RomoBoom
Posts: 45
Joined: Sat Sep 01, 2018 12:07 am

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Sun May 12, 2019 5:30 pm

i did everything that you guys said, and this happened :x
same error,
different code.
Attachments
error2.png
error2.png (156.32 KiB) Viewed 1320 times

RomoBoom
Posts: 45
Joined: Sat Sep 01, 2018 12:07 am

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Sun May 12, 2019 5:38 pm

ugh

i found it
if you see it, you have good eyes
Attachments
error3.png
(Hint: gkt)
error3.png (5.61 KiB) Viewed 1318 times

RomoBoom
Posts: 45
Joined: Sat Sep 01, 2018 12:07 am

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Sun May 12, 2019 5:42 pm

YASSSSSSS!!!! it worked!!! :D :D :D :D :D :D :D :D :lol: :lol: :lol: :) :D

THANK YOU EVERYONE!!!
Attachments
sucsess!.png
sucsess!.png (60.51 KiB) Viewed 1316 times

RomoBoom
Posts: 45
Joined: Sat Sep 01, 2018 12:07 am

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Sun May 12, 2019 5:48 pm

:D

just saying, this is a base for something bigger, i just had to get this right! :D

rich14
Posts: 3
Joined: Thu Oct 17, 2019 2:49 am

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Fri Nov 01, 2019 1:52 am

This book is a needed and well conceived addition to the Raspberry Pi theme of training future programmers. The bug that you have identified is a tragedy, because the student has found his sea legs (C legs) by working through the basic C lessons in the first half of the book, and is ready to jump into GUI programming with GTK --- but the first example (the foundation) FAILS!!! What a downer!!! In my case, I was a programmer and systems guy in Mfg. for 40+ years before retirement.. including Unix workstations. I have an idea for an app that I would like to develop for the Rpi using C & the GTK GUI. Here I am, "sucking wind," instead of sailing along! I'm sure that the two of us are not alone! Hundreds, or perhaps thousands, of our coding brothers and sisters are hanging up on this one, depending on Simon Long's book sales! I have tried a few ideas, described below.
Calling the attempt in the book to compile the author's C GTK program Try # 1, I tried two variations that didn't work, plus an attempt to compile the same "Tries" using the Ubuntu Mate 18,04.3 OS on my desktop. Ubuntu Mate failed in exactly the same way as you and I (and many other faithful vineyard toilers) discovered.on the Rpi.
My suspicion is that Simon Longs code is OK, but that a "regression" has crept into the C compiler preprocessor (maybe), or into the GTK routines (more likely) that we are trying to use in Simon's example.
Try #2 was to pipe the output from 'pkg-config --cflags --libs gtk+-2.0' into a named file in our working directory, and then to try the compile using the named file replacing the 'pkg-config ...' character string in gcc filename gtktest.c -o gtktest. The C preprocessor didn't object to the substitution, but still failed trying to find a include file.
The interesting thing is that the files being looked for are present in the correct directories!
Try #3 was to place all of the output include files from the "pkg-config --cflags --libs gtk+-2.0' phrase into the compile command gcc ..-v -pthread -I/usr/include/gtk-2.0 ... gtktest.c -o gtktest. Doing this produces a long compile command, and the C preproccessor again does not object to the syntax, but fails looking for different include files. I have saved the terminal output from all of this if you want to see it. I made these Tries on the RaspberryPi 4, first, and then on the Raspberry Pi 3b+. As I mentioned above, Ubuntu Mate also fails the same way. I'm thinking I should try again with Debian OS, because I seem to remember that both Raspbian and Ubuntu are derived from that OS. If Simon's GTK program also fails the same way on Debian, it would seem to exonerate Simon, Raspbian, UbuintuMate and Debian .... meaning that the problem is with GTK or the C compiler. Perhaps we could ask Simon to use his vast influence to get knowledgeable gurus to fix such basic flaws.

Best Regards From Northern Illinois, USA,
Dick Houser

rich14
Posts: 3
Joined: Thu Oct 17, 2019 2:49 am

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Sun Nov 10, 2019 4:14 am

As a continuation of my previous post, I went ahead and tried a couple of the latest Ubuntu downloads with Simon Long's exercises from Chapter 14 of his book, using GTK 2. I had no luck, so I followed the stream up to Debian, using the download "debian-live-10.1.0-amd64-xfce+nonfree.iso", installing as a Win 10 virtual machine. It was convenient to define a script to compile the gtktest.c exercise program, because the 'pkg-config --cflags --libs gtk+-2.0' string included in the gcc compile command for gtktest.c produced a diagnostic. However, if you replace that string with the lengthy include string outputs it produces a very lengthy gcc command which works! Putting that command into a script makes it manageable. I could then continue with Simon's lessons through Chapters 14 and 15.
So, Debian can be used to continue learning GTK C coding from Simon's very clear examples. My guess is that somewhere along the way in the past few years, the Debian developers introduced a regression that prevents the 'pkg-config...' string from being handled correctly, and around the same time, the Ubuntu and Raspbian developers either inherited or made another regression in the GTK 2.0 routines which produces the first problem that you reported and that Simon's other students are finding. We must leave these bugs to the developers to resolve, while we press on with our learning tasks. There is a surprising and hopeful amount of progress in these operating systems week to week. Personally, I have a Raspberry Pi 4 which I hope to do some 64 bit app dev on, for coming Arm SBCs.
Best Regards,
Dick Houser

User avatar
PeterO
Posts: 5073
Joined: Sun Jul 22, 2012 4:14 pm

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Sun Nov 10, 2019 5:31 am

The sad thing is that this book introduces people to GTK2 and not GTK3 :(
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
Paeryn
Posts: 2704
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Sun Nov 10, 2019 12:14 pm

rich14 wrote:
Sun Nov 10, 2019 4:14 am
It was convenient to define a script to compile the gtktest.c exercise program, because the 'pkg-config --cflags --libs gtk+-2.0' string included in the gcc compile command for gtktest.c produced a diagnostic. However, if you replace that string with the lengthy include string outputs it produces a very lengthy gcc command which works! Putting that command into a script makes it manageable. I could then continue with Simon's lessons through Chapters 14 and 15.
What was this diagnostic? By the sounds of it you were possibly trying to use the single quote ' to surround the pkg-config command rather than the backtick `. The difference is that the string inside backticks gets replaced by the output of running the contents of the string. It's a fundamental part of how the shell works, though it is generally better to enclose the command inside a dollar-bracket $() as it isn't as easily mis-read by people who aren't used to it (and the dollar-bracket nests nicely).

Code: Select all

gcc example.c -o example $(pkg-config --cflags --libs gtk+-2.0)
gcc example.c -o example `pkg-config --cflags --libs gtk+-2.0`
She who travels light — forgot something.

User avatar
PeterO
Posts: 5073
Joined: Sun Jul 22, 2012 4:14 pm

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Sun Nov 10, 2019 1:05 pm

rich14 wrote:
Fri Nov 01, 2019 1:52 am
The bug that you have identified is a tragedy, because the student has found his sea legs (C legs) by working through the basic C lessons in the first half of the book, and is ready to jump into GUI programming with GTK --- but the first example (the foundation) FAILS!!
Nonsense ! If you read the thread before making a reply you'll see the whole problem was the OPs repeated mistyping of "gtk" as "gkt".
All the examples in the book work fine.
PeterO

[moderator repaired typo "gtk" as "gtk" to "gtk" as "gkt" :mrgreen: its the Gnu Tool Kit or GTK]
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

rich14
Posts: 3
Joined: Thu Oct 17, 2019 2:49 am

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Mon Nov 11, 2019 2:26 am

Master Paeryn, Thanks So Much for clarifying the ' versus ` versus $(). The latter seems most preferable for clarity. You have set a number of us back on track. The Devil is Still in the Details! I'm determined to learn a good GUI dev system for the Pi. Could you tell us which GUI dev system the experienced RasPi programmers prefer?
Best Regards,
Dick Houser

User avatar
PeterO
Posts: 5073
Joined: Sun Jul 22, 2012 4:14 pm

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Mon Nov 11, 2019 8:58 am

PeterO wrote:
Sun Nov 10, 2019 1:05 pm
rich14 wrote:
Fri Nov 01, 2019 1:52 am
The bug that you have identified is a tragedy, because the student has found his sea legs (C legs) by working through the basic C lessons in the first half of the book, and is ready to jump into GUI programming with GTK --- but the first example (the foundation) FAILS!!
Nonsense ! If you read the thread before making a reply you'll see the whole problem was the OPs repeated mistyping of "gtk" as "gkt".
All the examples in the book work fine.
PeterO

[moderator repaired typo "gtk" as "gtk" to "gtk" as "gkt" :mrgreen: its the Gnu Tool Kit or GTK]
DO'H I type gtk so often I cant type it wrong ! :roll:

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
rpdom
Posts: 15412
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: i am trying to make a small window appear, with nothing in it, but it just isn't working.

Mon Nov 11, 2019 10:45 am

rich14 wrote:
Mon Nov 11, 2019 2:26 am
Master Paeryn, Thanks So Much for clarifying the ' versus ` versus $(). The latter seems most preferable for clarity.
Not just clarity, but it can also be nestable, which doesn't work with the `command` form.

Code: Select all

echo $(ls -lh $(ls myfile))
Not a good example, but you should get the idea.

Return to “C/C++”