LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-14-2010, 01:55 AM   #1
nainesh
LQ Newbie
 
Registered: May 2010
Location: Ahmedabad-Gujarat
Distribution: Fedora
Posts: 27

Rep: Reputation: 0
Question ‘GTK_TEXT’ was not declared in this scope


Hi All,

I am getting error message when i am using gtktext widget. here i am posting my code as well as error messgae.

Code is here.

1 /* hello-gtk.c */
2
3 #include <gtk/gtk.h>
4 #include <gtk/gtktext.h>
5
6 gint QuitProg(GtkWidget *widget, gpointer gdata){
7
8 gtk_main_quit();
9 return (FALSE);
10
11 }
12
13 int main (int argc, char *argv[]){
14
15 GtkWidget *window;
16 GtkWidget *text_pane;
17
18 gtk_init(&argc, &argv); /*required initializing */
19
20 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
21 gtk_widget_set_usize(window,200,100);
22 gtk_window_set_title(GTK_WINDOW(window) , "First Program");
23 gtk_container_set_border_width(GTK_CONTAINER(window),5);
24
25 gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC(QuitProg), NULL);
26
27 text_pane = gtk_text_new(NULL, NULL);
28 gtk_text_set_editable(GTK_TEXT(text_pane) , FALSE);
29 gtk_container_add(GTK_CONTAINER(window) , text_pane);
30 gtk_widget_realize(text_pane);
31 gtk_text_insert(GTK_TEXT(text_pane) , NULL , NULL , NULL, "Hello Linux World \n\n" , -1);
32
33 gtk_widget_show(text_pane);
34 gtk_widget_show (window);
35
36 gtk_main ();
37
38 }


i am trying it to compile by this command.

g++ -o hello-gtk hello-gtk.c `pkg-config gtk+-2.0 --cflags --libs`

but getting error messages

hello-gtk.c: In function ‘int main(int, char**)’:
hello-gtk.c:27: error: ‘gtk_text_new’ was not declared in this scope
hello-gtk.c:28: error: ‘GTK_TEXT’ was not declared in this scope
hello-gtk.c:28: error: ‘gtk_text_set_editable’ was not declared in this scope
hello-gtk.c:31: error: ‘gtk_text_insert’ was not declared in this scope
 
Old 09-14-2010, 07:57 PM   #2
14moose
Member
 
Registered: May 2010
Posts: 83

Rep: Reputation: Disabled
Hi -

On my system, the definition for GTK_TEXT happens to be here:
Quote:
/opt/gnome/include/gtk-2.0/gtk/gtktext.h =>
#define GTK_TEXT(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT, Gt
kText))
Similarly, type prototype for gtk_text_new() is in the same header, gtktext.h =>
Quote:
GtkWidget* gtk_text_new (GtkAdjustment *hadj,
GtkAdjustment *vadj);
So clearly, you seem to be doing everything right.

SUGGESTION:
1. type "pkg-config gtk+-2.0 --cflags --libs" from the command line

2. Make sure it has a "-I" switch that corresponds to your install directory:
Quote:
EXAMPLE:
-I/opt/gnome/include/gtk-2.0
3. Check the gtktext.h file in the directory for GTK_TEXT, gtk_text_new(), and friends.

'Hope that helps
 
1 members found this post helpful.
Old 09-15-2010, 12:29 AM   #3
nainesh
LQ Newbie
 
Registered: May 2010
Location: Ahmedabad-Gujarat
Distribution: Fedora
Posts: 27

Original Poster
Rep: Reputation: 0
Thanks 14moose,

I have tried two compilers with your suggestions, But still different errors.Please find here both g++ & gcc commands and errors.

Command:- g++ -o hello-gtk hello-gtk.c `pkg-config gtk+-2.0 --cflags --libs` -l /user/include/gtk-2.0

Errors:- hello-gtk.c: In function ‘int main(int, char**)’:
hello-gtk.c:27: error: ‘gtk_text_new’ was not declared in this scope
hello-gtk.c:28: error: ‘GTK_TEXT’ was not declared in this scope
hello-gtk.c:28: error: ‘gtk_text_set_editable’ was not declared in this scope
hello-gtk.c:31: error: ‘gtk_text_insert’ was not declared in this scope

Command:- gcc -o hello-gtk hello-gtk.c `pkg-config gtk+-2.0 --cflags --libs` -l /user/include/gtk-2.0

Errors:- hello-gtk.c: In function ‘main’:
hello-gtk.c:27: warning: assignment makes pointer from integer without a cast
/usr/bin/ld: cannot find -l/user/include/gtk-2.0/
collect2: ld returned 1 exit status

By -l option i mean to give the path for the GTK's header files which they are resides. am i right ?
 
Old 09-15-2010, 10:11 AM   #4
14moose
Member
 
Registered: May 2010
Posts: 83

Rep: Reputation: Disabled
Hi -

1. Please type "pkg-config gtk+-2.0 --cflags --libs" from a command prompt, and show us the output.

2. In typical *nix fashion, the directory is actually "/usr" (not "/user").

3. "-I" (capital-eye) is so the compiler can find your header (.h) files.

"-l" (little-ell) is so the linker can find your libraries (.a or .so).

Neither one has a space after it:

EXAMPLES:
-I/usr/include/gtk-2.0
-l/usr/lib/gtk-2.0

Pkg-config should "know" which flags to use. Please run the command and post the output.

Thank you in advance
 
Old 09-16-2010, 12:19 AM   #5
nainesh
LQ Newbie
 
Registered: May 2010
Location: Ahmedabad-Gujarat
Distribution: Fedora
Posts: 27

Original Poster
Rep: Reputation: 0
Thanks 14moose,
First thanks to care fully read my post.

i have corrected here my fault. But still i am getting errors at compiling. now i will explaining here my full gtk structure as well as a new commands i have fired here.

first see here my directory structre of gtk-2.0

[root@Nainesh-Linux GTK]# ls /usr/include/gtk-2.0/ -liah
total 44K
5916240 drwxr-xr-x. 6 root root 4.0K 2009-09-04 06:56 .
5881857 drwxr-xr-x. 143 root root 16K 2010-09-08 12:06 ..
5916241 drwxr-xr-x. 2 root root 4.0K 2009-10-27 13:34 gdk
5916242 drwxr-xr-x. 2 root root 4.0K 2009-10-27 13:34 gdk-pixbuf
5916243 drwxr-xr-x. 2 root root 4.0K 2009-10-27 13:34 gdk-pixbuf-xlib
5916290 drwxr-xr-x. 2 root root 12K 2010-09-14 15:20 gtk

[root@Nainesh-Linux GTK]# gcc -o hello-gtk hello-gtk.c `pkg-config gtk+-2.0 --cflags --libs` -I /usr/include/gtk-2.0/
hello-gtk.c: In function ‘main’:
hello-gtk.c:27: warning: assignment makes pointer from integer without a cast
/tmp/ccqdXCgZ.o: In function `main':
hello-gtk.c.text+0x11a): undefined reference to `GTK_TEXT'
hello-gtk.c.text+0x167): undefined reference to `GTK_TEXT'
collect2: ld returned 1 exit status


[root@Nainesh-Linux GTK]# g++ -o hello-gtk hello-gtk.c `pkg-config gtk+-2.0 --cflags --libs` -I /usr/include/gtk-2.0/
hello-gtk.c: In function ‘int main(int, char**)’:
hello-gtk.c:27: error: ‘gtk_text_new’ was not declared in this scope
hello-gtk.c:28: error: ‘GTK_TEXT’ was not declared in this scope
hello-gtk.c:28: error: ‘gtk_text_set_editable’ was not declared in this scope
hello-gtk.c:31: error: ‘gtk_text_insert’ was not declared in this scope
 
Old 09-16-2010, 01:46 PM   #6
14moose
Member
 
Registered: May 2010
Posts: 83

Rep: Reputation: Disabled
Let me ask you again:

1. *Please* post the output of "pkg-config gtk+-2.0 --cflags --libs"!

2. Please *don't* put a space between "-I" and "/usr/include/gtk-2.0/"!
 
Old 09-17-2010, 01:57 AM   #7
nainesh
LQ Newbie
 
Registered: May 2010
Location: Ahmedabad-Gujarat
Distribution: Fedora
Posts: 27

Original Poster
Rep: Reputation: 0
Yes 14Moose

get here my out put of "pkg-config gtk+-2.0 --cflags --libs"
[root@Nainesh-Linux C]# pkg-config gtk+-2.0 --cflags --libs
-I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglib-2.0

Also find here out put without space between "-I" and "/usr/include/gtk-2.0"

[root@Nainesh-Linux GTK]# gcc -o hello-gtk hello-gtk.c `pkg-config gtk+-2.0 --cflags --libs` -I/usr/include/gtk-2.0
hello-gtk.c: In function ‘main’:
hello-gtk.c:28: warning: assignment makes pointer from integer without a cast
/tmp/ccYx3YWG.o: In function `main':
hello-gtk.c.text+0x11a): undefined reference to `GTK_TEXT'
hello-gtk.c.text+0x167): undefined reference to `GTK_TEXT'
collect2: ld returned 1 exit status

[root@Nainesh-Linux GTK]# g++ -g -o hello-gtk hello-gtk.c `pkg-config gtk+-2.0 --cflags --libs` -I/usr/include/gtk-2.0
hello-gtk.c: In function ‘int main(int, char**)’:
hello-gtk.c:28: error: ‘gtk_text_new’ was not declared in this scope
hello-gtk.c:29: error: ‘GTK_TEXT’ was not declared in this scope
hello-gtk.c:29: error: ‘gtk_text_set_editable’ was not declared in this scope
hello-gtk.c:32: error: ‘gtk_text_insert’ was not declared in this scope
 
Old 09-17-2010, 12:43 PM   #8
14moose
Member
 
Registered: May 2010
Posts: 83

Rep: Reputation: Disabled
nainesh -

Good. Progress Thank you!

Now....

1. As I said above, "pkg-config" should "know" where your GTK 2.0 headers and libraries are. This is where your "pkg-config" thinks they're installed on your system:

Code:
-I/usr/include/gtk-2.0 \
   -I/usr/lib/gtk-2.0/include \
   -I/usr/include/atk-1.0 \
   -I/usr/include/cairo \
   -I/usr/include/pango-1.0 \
   -I/usr/include/glib-2.0 \
   -I/usr/lib/glib-2.0/include \
   -I/usr/include/pixman-1 \
   -I/usr/include/freetype2 \
   -I/usr/include/libpng12 \
   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglib-2.0
2. As I also said above, the first error, "hello-gtk.c:28: error: ‘GTK_TEXT’ was not declared in this scope" is a COMPILE error. It should not occur if you have the right include files (e.g. the right "-I" path).

Q: Do you have a file "/usr/include/gtk-2.0/gtk/gtktext.h"?

Q: Does your gtktext.h contain a line that looks like this?
Code:
#define GTK_TEXT(obj)                  (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT, Gt
kText))
3. The next error, "hello-gtk.c.text+0x11a): undefined reference to `GTK_TEXT'", is a LINK error. It's completely separate and distinct from the first one ("‘GTK_TEXT’ was not declared in this scope").

But let's assume for now that it might be a side-effect of 2), the compile error.

Please answer the questions in "2)" above, post back the results, and we'll take it from there.

'Hope that helps!

PS:
Hint:
if you fix the compile error, but get link errors, then we'll go BACK to your "pkg-conf" output, and start looking at your "-L" (library path) flags.

But GTK_TEXT should *never* occur as a link error (like you're getting), because it's a #define (not a translation unit).

So again - let's focus on getting a clean compile. Please resolve the issues in 2) first.

Last edited by 14moose; 09-17-2010 at 12:46 PM.
 
Old 09-18-2010, 12:18 AM   #9
nainesh
LQ Newbie
 
Registered: May 2010
Location: Ahmedabad-Gujarat
Distribution: Fedora
Posts: 27

Original Poster
Rep: Reputation: 0
Dear 14Moose,
As per your second question please find here my gtktext.h path as well as containing GTK_TEXT macro.

[root@Nainesh-Linux GTK]# cat -n /usr/include/gtk-2.0/gtk/gtktext.h |grep "#define GTK_TEXT(obj)"
39 #define GTK_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT, GtkText))
 
Old 09-18-2010, 01:06 AM   #10
14moose
Member
 
Registered: May 2010
Posts: 83

Rep: Reputation: Disabled
Hi -

Here's the actual problem:
Quote:
http://www.gtk.org/api/2.6/gtk/GtkText.html

Warning

GtkText is deprecated and unsupported. It is known to be buggy. To use it, you must define the symbol GTK_ENABLE_BROKEN prior to including the GTK+ header files. Use GtkTextView instead.
And here's how to compile your program:
Code:
g++ -o hello-gtk  -DGTK_ENABLE_BROKEN hello-gtk.c `pkg-config gtk+-2.0 --cflags --libs`
(the syntax would be identical for gcc)
 
Old 09-20-2010, 12:51 AM   #11
nainesh
LQ Newbie
 
Registered: May 2010
Location: Ahmedabad-Gujarat
Distribution: Fedora
Posts: 27

Original Poster
Rep: Reputation: 0
Thanks 14Moose,

You have solved my problem. my programme now compiled and runnig. thanks a lot. please be in touch can you give me your email id. so, i can contact you if facing any problem in future.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem compiling (error: ‘strcmp’ was not declared in this scope) beboppinbobby Linux - Newbie 4 12-19-2009 01:33 AM
aria2, ‘assert’ was not declared in this scope , compiler error adityasharma Linux - Newbie 4 07-31-2009 05:51 AM
Compiling tesseract-2.03: error: ‘INT32’ was not declared in this scope J_Szucs Linux - Software 10 03-05-2009 02:35 PM
Error Prompt - 'Execute_command was not declared in this scope. Please help! thhuang Linux - Newbie 1 11-05-2007 12:38 AM
ltoa not declared in the scope lucky6969b Programming 3 12-23-2005 08:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration