⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkfaq-4.html

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9"> <TITLE>GTK+ FAQ: Development with GTK+: the begining</TITLE> <LINK HREF="gtkfaq-5.html" REL=next> <LINK HREF="gtkfaq-3.html" REL=previous> <LINK HREF="gtkfaq.html#toc4" REL=contents></HEAD><BODY BGCOLOR="#FFFFFF"><A HREF="gtkfaq-5.html">Next</A><A HREF="gtkfaq-3.html">Previous</A><A HREF="gtkfaq.html#toc4">Contents</A><HR NOSHADE><H2><A NAME="s4">4. Development with GTK+: the begining</A></H2><H2><A NAME="ss4.1">4.1 How do I get started?</A></H2><P>So, after you have installed GTK+ there are a couple of things that canease you into developing applications with it. There is theGTK+ Tutorial <A HREF="http://www.gtk.org/tutorial/">&lt;http://www.gtk.org/tutorial/&gt;</A>, which is undergoing development. This will introduce you to writing applications using C.<P>The Tutorial doesn't (yet) contain information on all of the widgetsthat are in GTK+. For example code on how to use the basics of all theGTK+ widgets you should look at the file gtk/testgtk.c (and associatedsource files) within the GTK+ distribution. Looking at these exmaples willgive you a good grounding on what the widgets can do.<P><H2><A NAME="ss4.2">4.2 I tried to compile a small <CODE>Hello World</CODE> of mine, but it failed. Any clue?</A></H2><P>Since you are good at coding, we will not deal with compile time error here :).<P>The classic command line to compile a GTK+ based program is<P><PRE>gcc -o myprg [c files list] `gtk-config --cflags --libs`</PRE><P>You should notice the backquote character which is used in this command line.A common mistake when you start a GTK+ based development is to use quote instead of backquotes. If you do so, the compiler will complain about an unknown file called 'gtk-config --cflags --libs'. The text inbackquotes is an instruction to your shell to substitute the output ofexecuting this text into the command line.<P>The command line above ensure that:<UL><LI>the correct C compiler flags will be used to compile the program(including the complete C header directory list)</LI><LI>your program will be linked with the needed libraries.</LI></UL><P><H2><A NAME="ss4.3">4.3 What about using the <CODE>make</CODE> utility?</A></H2><P>This is a sample makefile which compile a GTK+ based program:<P><BLOCKQUOTE><CODE><PRE># basic GTK+ app makefileSOURCES = myprg.c foo.c bar.cOBJS    = ${SOURCES:.c=.o}CFLAGS  = `gtk-config --cflags`LDADD   = `gtk-config --libs`CC      = gccPACKAGE = myprgall : ${OBJS}        ${CC} -o ${PACKAGE} ${OBJS} ${LDADD}.c.o:        ${CC} ${CFLAGS} -c $&lt;# end of file</PRE></CODE></BLOCKQUOTE><P>For more information about the <CODE>make</CODE> utility, you should read either therelated man page or the relevant info file.<P><H2><A NAME="ss4.4">4.4 I use the backquote stuff in my makefiles, but my make process failed.</A></H2><P>The backquote construction seems to not be accepted by some old <CODE>make</CODE>utilities. If you use one of these, the make process will probably fail.In order to have the backquote syntax working again, you should use theGNU make utility (get it on the GNU ftp server at<A HREF="ftp://ftp.gnu.org/">ftp://ftp.gnu.org/</A>).<P><H2><A NAME="ss4.5">4.5 I want to add some configure stuff, how could I do this?</A></H2><P>To use autoconf/automake, you must first install the relevant packages. Theseare:<P><UL><LI>the m4 preprocessor v1.4 or better</LI><LI>autoconf v2.13 or better</LI><LI>automake v1.4 or better</LI></UL><P>You'll find these packages on the GNU main ftp server (<A HREF="ftp://ftp.gnu.org/">ftp://ftp.gnu.org/</A>) or on any GNU mirror.<P>In order to use the powerfull autoconf/automake scheme, you must createa configure.in which may look like:<P><BLOCKQUOTE><CODE><PRE>dnl Process this file with autoconf to produce a configure script.dnl configure.in for a GTK+ based programAC_INIT(myprg.c)dnlAM_INIT_AUTOMAKE(mypkbname,0.0.1)dnlAM_CONFIG_HEADER(config.h)dnldnl Checks for programs.AC_PROG_CC dnl check for the c compilerdnl you should add CFLAGS="" here, 'cos it is set to -g by PROG_CCdnl Checks for libraries.AM_PATH_GTK(1.2.0,,AC_MSG_ERROR(mypkgname 0.1 needs GTK))dnlAC_OUTPUT(        Makefile)dnl</PRE></CODE></BLOCKQUOTE><P>You must add a Makefile.am file:<P><BLOCKQUOTE><CODE><PRE>bin_PROGRAMS    = myprgmyprg_SOURCES   = myprg.c foo.c bar.cINCLUDES        = @GTK_CFLAGS@LDADD           = @GTK_LIBS@CLEANFILES      = *~DISTCLEANFILES  = .deps/*.P</PRE></CODE></BLOCKQUOTE><P>then, to use these, simply type the following commands:<P><PRE>aclocalautoheaderautoconfautomake --add-missing --include-deps --foreign </PRE><P>For further informations, you should look at the autoconf and the automakedocumentation (the shipped info files are really easy to understand, and thereare plenty of web resources that deal with autoconf and/or automake).<P><H2><A NAME="ss4.6">4.6 I try to debug my GTK+ application with gdb, but it hangs my X server when I hit some breakpoint. Any Idea ?</A></H2><P>From Federico Mena Quintero:<BLOCKQUOTE>X is not locked up.  It is likely that you are hitting a breakpointinside a callback that is called from a place in Gtk that has a mousegrab.<P>Run your program with the "--sync" option; it will make it easier todebug. Also, you may want to use the console for running thedebugger, and just let the program run in another console with the Xserver.</BLOCKQUOTE><P>Eric Mouw had another solution:<BLOCKQUOTE>An old terminal connected to an otherwise unused serial port is also greatfor debugging X programs. Old vt100/vt220 terminals are dirt cheap but abit hard to get (here in The Netherlands, YMMV).</BLOCKQUOTE><P><HR NOSHADE><A HREF="gtkfaq-5.html">Next</A><A HREF="gtkfaq-3.html">Previous</A><A HREF="gtkfaq.html#toc4">Contents</A></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -