LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1029|回复: 10

helloworld的GTK版

[复制链接]
发表于 2005-5-9 18:32:53 | 显示全部楼层 |阅读模式
打字比较慢,敲了半天,但就是成功不了,老说找不到gtk/gtk+.h
[php]#include<stdio.h>
#include<gtk/gtk.h>
static GtkWidget *entry;

void
PrintAndExit (GtkWidget *widget,GtkWidget*window )
{
        char        *str;

        str=gtk_entry_text(GTK_ENTRY(entry)        );
        if (str !=  (char*) NULL)
                printf( "%s\n",str);

        gtk_widget_destroy(window);
        gtk_main_quit ();
}
void
PrintByeAndExit (GtkWidget*widget,gpointer date)
{
        printf( "Goodbye, world!\n");
        gtk_exit(0);
}
int
main( int argc,char *argv[])
{
        GtkWidget*window , *label,*vbox,*hbox,*button,*separator;

        gtk_set_local ();
        gtk_init (&argc,&argv);

        window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_policy(GTK_WINDOW(window),FALSE,FALSE,FALSE);

        gtk_signal_connect (GTK_OBJECT(window), "destroy",
                                GTK_SIGNAL_FUNC(PrintByeAndExit),NULL);

        gtk_window_set_title (GTK_WINDOW (window), "Hello Gtk+");
        gtk_container_border_width(GTK_CONTAINER(window),0);
       
        vbox=gtk_vbox_new (FALSE, 0);
        gtk_container_add(GTK_CONTAINER(window),vbox);

        hbox=gtk_hbox_new(FALSE, 0);
        gtk_box_pack_start (GTK_BOX (vbox),hbox,FALSE, FALSE, 0);
        label=gtk_label_new( "Enter a message:" );
        gtk_box_pack_start (GTK_BOX (vbox),hbox, FALSE, FALSE, 0);

        label=gtk_label_new( "Enter a message:" );
        gtk_box_pack_start (GTK_BOX(hbox), label,FALSE,FALSE, 0);
        entry=gtk_entry_new ();
        gtk_entry_set_text (GTK_ENTRY(entry), "");
        gtk_editable_select_region(GTK_EDITALBLE (entry),0,-1);
        gtk_box_pack_start (GTK_BOX (hbox),entry,FALSE,FALSE,0);

        separator=gtk_hseparator_new();
        gtk_box_pack_start (GTK_BOX(vbox),separator,FALSE,FALSE,0);

        button=gtk_button_new_with_label ("rint");
        gtk_signal_connect_object (GTK_OBJECT(button), "clicked",
                        GTK_SIGNAL_FUNC(PrintAndExit),GTK_OBJECT(window));
        gtk_box_pack_start (GTK_BOX(vbox),button,FALSE,FALSE,0);
        GTK_WIDGET_SET_FLAGS (button,GTK_CAN_DEFAULT);
        gtk_widget_grab_default (button);

        gtk_widget_show_all (window);
        gtk_main();
        return(0);
}[/php]
发表于 2005-5-10 00:02:00 | 显示全部楼层
实在搞不懂,anjuta也是这样找不到gtk/gtk.h,哈
回复 支持 反对

使用道具 举报

发表于 2005-5-10 14:45:55 | 显示全部楼层
我的anjuta提示没有gnomeui-2.0,哪里有下载?
luopeng@ubuntu:~$ cd Projects/heloworld
luopeng@ubuntu:~/Projects/heloworld$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets $(MAKE)... yes
checking for working aclocal-1.4... found
checking for working autoconf... found
checking for working automake-1.4... found
checking for working autoheader... found
checking for working makeinfo... missing
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for strerror in -lcposix... no
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ANSI C... (cached) none needed
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for ANSI C header files... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking for a sed that does not truncate output... /bin/sed
checking whether ln -s works... yes
checking how to recognise dependent libraries... pass_all
checking command to parse /usr/bin/nm -B output... ok
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking for ranlib... ranlib
checking for strip... strip
checking for objdir... .libs
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.lo... yes
checking if gcc supports -fno-rtti -fno-exceptions... no
checking whether the linker (/usr/bin/ld) supports shared libraries... yes
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether -lc should be explicitly linked in... no
creating libtool
checking for pkg-config... /usr/bin/pkg-config
checking for libgnomeui-2.0 gtk+-2.0... Package libgnomeui-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libgnomeui-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libgnomeui-2.0' found
回复 支持 反对

使用道具 举报

发表于 2005-5-11 13:03:47 | 显示全部楼层
你要连接gtk库的啊。
我好久不用了,似乎是`pkg-config --clibs --cflags gtk+-2.0`
注意是Tab上面那个,不是单引号
回复 支持 反对

使用道具 举报

发表于 2005-5-11 16:50:08 | 显示全部楼层
还是不行!
回复 支持 反对

使用道具 举报

发表于 2005-5-11 16:57:00 | 显示全部楼层
看了一下出错提示,好象是libgnomeui这个库找不到,或者glade中去掉libgnomeui支持,或者把它的.pc文件拷贝到pkg-config能找到的路径下。
回复 支持 反对

使用道具 举报

发表于 2005-5-11 17:04:57 | 显示全部楼层
我也遇到过你的那种情况,如果你确认你安装了gnomeui且pkgconfig路径正确的化,看看里面是不是有gnomeui-2.*之类的,如果有建个gnomeui-2.0.pc的链接就可以了
回复 支持 反对

使用道具 举报

发表于 2005-5-13 09:24:51 | 显示全部楼层
你这样编译试试,  gcc helloworld.c -g -o helloworld `pkg-config gtk+-2.0 --cflags --libs`
是单引号!
回复 支持 反对

使用道具 举报

发表于 2005-5-13 12:28:35 | 显示全部楼层
关于库,我的blog上有两篇文章
你去看一下有没有帮助
我的blog: my.chinaunix.net/nait
good luck!
回复 支持 反对

使用道具 举报

发表于 2005-5-13 14:07:37 | 显示全部楼层
我的系统中没有libgnomeui-2.0,哪里有下载?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表