 |
GTK+ Forums Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
|
|
|
| Author |
Message |
|
|
alpha_gamma
Joined: 24 Feb 2007 Posts: 3
|
Posted: Sat Feb 24, 2007 2:48 pm Post subject: Problem w/ code example from Harlow book |
|
|
Hello,
I am new to Gtk+ but have been using C++ for a few years.
I picked up the book, "Developing Linux Applications with GTK+ and GDK" by Eric Harlow and have been trying out some of the code examples from the book. In chapter 7 there is a Calculator example that compiles with no problem, but when running the application I try to add/subtract/multiply numbers nothing happens. In the book on pg. 136 he says
" ...when the user types in '=', the calculator looks up the previous command ('+'), the number saved in the buffer ('235'), and the number in the display '111'. The calculator must then perform addition of '235' and '111'. "
According to the author this application should add/subtract/... numbers but when I try it doesn't
The code examples for the book can be downloaded from this site
http://www.netbrain.com/~brain/book/
....this application "The GTK Calculator" is under Chapter 7
I'll add that when I compiled the code I got numerous warning about 'Implicit Declarations' for C language
functions like strcpy, strlen, atof and strcmp.
I would like to find out why this program will not perform arithmetic. Can someone help me out and point out where
the errors are?
Andrew |
|
| Back to top |
|
 |
openldev Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 376 Location: State College, Pennsylvania
|
Posted: Sat Feb 24, 2007 3:32 pm Post subject: |
|
|
Well, the first thing that you should know is that his book is based upon GTK+ 1.2. Most distributions come with GTK+ 2.10, which is the current release. Actually, almost every book on GTK+ is on version 1.2. Foundations of GTK+ Development, found at http://www.gtkbook.com, is the only book available on GTK+ 2.x. (In order to have full disclosure, I wrote this book.)
One of the reasons this may not be working is because of conflicts in libraries. It does not run on my system if I compile it against my version of GTK+. However, if I install GTK+ 1.2 alongside my version, it does compile and run.
As for your warnings, it is because he did not include <string.h> or <stdlib.h>. Compilers are stricter about this now, especially GCC. The application doesn't work because those functions cannot be found.
Lastly, his method of compiling is with gtk-config, but this is depreciated. You should be compiling with pkg-config, although the book will not cover it because the application did not exist when the book was released in 1999. I would recommend that in the future, when you buy a book, check the publication date. Even if you learn GTK+ from this book, you are going to be 5 years behind the game because there were an immense number of changes between GTK+ 1.2 and 2.0 (and beyond).[/url] |
|
| Back to top |
|
 |
alpha_gamma
Joined: 24 Feb 2007 Posts: 3
|
Posted: Sat Feb 24, 2007 7:24 pm Post subject: |
|
|
Thank you very much Andrew,
I have a few books on Gtk+ but they are older like the Harlow book. I'll be sure to buy your book when released
so I can be educated on the most current Gtk+ 2 libraries.
I will look for a way to install Gtk+ 1.2 along with Gtk+ 2.0 so I can run these older applications and
at least make some use out of the books.
Actually, I did use GCC to compile the code and that is probably why I got the complaints. Thank you
for telling me about that.
Thanks again for responding to a beginner's post, I do appreciate it.
Andrew |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 426 Location: Portland, OR USA
|
Posted: Sat Feb 24, 2007 10:51 pm Post subject: |
|
|
| I also have that Harlow book-- it has MANY MANY things that are obsolete. I only use it as a historical reference. Get Andrew's book... it's all up to date. |
|
| Back to top |
|
 |
openldev Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 376 Location: State College, Pennsylvania
|
Posted: Sat Feb 24, 2007 11:04 pm Post subject: |
|
|
| Micah's my TR, so he would know! :) |
|
| Back to top |
|
 |
alpha_gamma
Joined: 24 Feb 2007 Posts: 3
|
Posted: Sun Feb 25, 2007 12:36 am Post subject: |
|
|
I installed Gtk 1.2 plus added <stdlibh> and <string.h> to Harlow's Calculator application, plus added pkg-congig
to the Makefile and it runs very well.
I just graduated from College with a CS degree but with never being hired it is hard to find entry level work. I was hoping to make my own calculator and base it loosely on Harlow's calculator and add it to sourceforge. I'm hoping to put an application onto a CVS so I can put it on my resume. If I design a calculator like Harlow's it would look like I am using deprecated library files. I'll be sure to get Andrew's book so I can make the app more current.
I have been looking for projects to join on sourceforge but I have not been getting answers from the emails I send out to the project managers. It's kind of like applying for a job, you know.
Next week I'll be doing a second interview for an entry job designing casino software, so that looks hopeful.
Thanks again Micah and Andrew, hope your having a nice weekend.
Regards,
Andrew |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 426 Location: Portland, OR USA
|
Posted: Sun Feb 25, 2007 1:48 am Post subject: |
|
|
Andrew's book has many, great example applications and snippets.
Good luck with the interview. |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group CodeBB 1.0 Beta 2
|