How to love gcc

One of the first thing many students starting to work on Mozilla learn is that they don't know enough about the build tool-chain.  For example: I'm working on fixing a Mozilla bug on OS X bug right now, and here's what happens when I make a change to the file where I'm working and it gets rebuilt:

c++ -o nsMessengerOSXIntegration.o -c -I../../../mozilla/dist/include/system_wrappers -include /Users/dave/moz/comm-central/src/mozilla/config/gcc_hidden.h -DMOZ_LDAP_XPCOM -DMOZILLA_INTERNAL_API -DMOZ_THUNDERBIRD=1 -DOSTYPE=\"Darwin9.7.0\" -DOSARCH=Darwin -DHAVE_MOVEMAIL  -I/Users/dave/moz/comm-central/src/mailnews/base/src -I. -I../../../mozilla/dist/include/xpcom -I../../../mozilla/dist/include/alerts -I../../../mozilla/dist/include/string -I../../../mozilla/dist/include/necko -I../../../mozilla/dist/include/dom -I../../../mozilla/dist/include/appshell -I../../../mozilla/dist/include/toolkitcomps -I../../../mozilla/dist/include/appcomps -I../../../mozilla/dist/include/uconv -I../../../mozilla/dist/include/intl -I../../../mozilla/dist/include/htmlparser -I../../../mozilla/dist/include/widget -I../../../mozilla/dist/include/docshell -I../../../mozilla/dist/include/rdf -I../../../mozilla/dist/include/gfx -I../../../mozilla/dist/include/thebes -I../../../mozilla/dist/include/layout -I../../../mozilla/dist/include/content -I../../../mozilla/dist/include/mailnews -I../../../mozilla/dist/include/locale -I../../../mozilla/dist/include/unicharutil -I../../../mozilla/dist/include/msgbaseutil -I../../../mozilla/dist/include/webshell -I../../../mozilla/dist/include/txmgr -I../../../mozilla/dist/include/msgcompose -I../../../mozilla/dist/include/msgdb -I../../../mozilla/dist/include/uriloader -I../../../mozilla/dist/include/pref -I../../../mozilla/dist/include/msglocal -I../../../mozilla/dist/include/msgimap -I../../../mozilla/dist/include/mork -I../../../mozilla/dist/include/msgnews -I../../../mozilla/dist/include/addrbook -I../../../mozilla/dist/include/mime -I../../../mozilla/dist/include/mimetype -I../../../mozilla/dist/include/windowwatcher -I../../../mozilla/dist/include/webbrwsr -I../../../mozilla/dist/include/exthandler -I../../../mozilla/dist/include/xulapp -I../../../mozilla/dist/include/caps -I../../../mozilla/dist/include/xpconnect -I../../../mozilla/dist/include/js -I../../../mozilla/dist/include/mozldap -I../../../mozilla/dist/include   -I../../../mozilla/dist/include/msgbase../../../mozilla/nsprpub/config/nspr-config --prefix=../../../mozilla/dist --includedir=../../../mozilla/dist/include/nspr --cflags-I/usr/X11/include   -fPIC  -I/usr/X11/include -fno-rtti -fno-exceptions -Wall -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-invalid-offsetof -Wno-long-long -fno-strict-aliasing -fpascal-strings -fno-common -fshort-wchar -pthread -I/Developer/Headers/FlatCarbon -pipe  -DDEBUG -D_DEBUG -DDEBUG_dave -DTRACING -g  -I/usr/X11/include -DMOZILLA_CLIENT -include ../../../mozilla-config.h -Wp,-MD,.deps/nsMessengerOSXIntegration.pp /Users/dave/moz/comm-central/src/mailnews/base/src/nsMessengerOSXIntegration.cpp /Users/dave/moz/comm-central/src/mailnews/base/src/nsMessengerOSXIntegration.cpp: In member function ‘nsresult nsMessengerOSXIntegration::BadgeDockIcon()’: /Users/dave/moz/comm-central/src/mailnews/base/src/nsMessengerOSXIntegration.cpp:577: warning: ‘FMGetFontFamilyFromName’ is deprecated (declared at /System/Library/Frameworks/ApplicationServices.framework/Frameworks/QD.framework/Headers/Fonts.h:813) /Users/dave/moz/comm-central/src/mailnews/base/src/nsMessengerOSXIntegration.cpp:577: warning: ‘FMGetFontFamilyFromName’ is deprecated (declared at /System/Library/Frameworks/ApplicationServices.framework/Frameworks/QD.framework/Headers/Fonts.h:813) /Users/dave/moz/comm-central/src/mailnews/base/src/nsMessengerOSXIntegration.cpp:580: warning: ‘FMGetFontFromFontFamilyInstance’ is deprecated (declared at /System/Library/Frameworks/ApplicationServices.framework/Frameworks/QD.framework/Headers/Fonts.h:988) /Users/dave/moz/comm-central/src/mailnews/base/src/nsMessengerOSXIntegration.cpp:583: warning: ‘FMGetFontFromFontFamilyInstance’ is deprecated (declared at /System/Library/Frameworks/ApplicationServices.framework/Frameworks/QD.framework/Headers/Fonts.h:988) rm -f libmsgbase_s.a ar cr libmsgbase_s.a nsMessenger.o nsMessengerBootstrap.o nsMsgMailSession.o nsMsgAccountManager.o nsMsgAccount.o nsCopyMessageStreamListener.o nsMsgRDFDataSource.o nsMsgFolderDataSource.o nsMsgAccountManagerDS.o nsMsgRDFUtils.o nsMsgBiffManager.o nsMsgPurgeService.o nsMsgCopyService.o nsMsgFolderCache.o nsMsgFolderCacheElement.o nsMsgFolderCompactor.o nsMsgStatusFeedback.o nsMsgWindow.o nsMsgServiceProvider.o nsSubscribeDataSource.o nsSubscribableServer.o nsMsgPrintEngine.o nsStatusBarBiffManager.o nsMsgDBView.o nsMsgThreadedDBView.o nsMsgSpecialViews.o nsMsgQuickSearchDBView.o nsMsgSearchDBView.o nsMsgXFVirtualFolderDBView.o nsMsgXFViewThread.o nsMsgGroupThread.o nsMsgGroupView.o nsMsgOfflineManager.o nsMsgProgress.o nsMessengerContentHandler.o nsSpamSettings.o nsCidProtocolHandler.o nsMsgContentPolicy.o nsMsgTagService.o nsMsgFolderNotificationService.o nsMailDirProvider.o nsMessengerOSXIntegration.o ranlib libmsgbase_s.a

Still with me?  That's one C++ file being altered.  In a full build screens of output like that scroll by for 30 to 60 minutes.  Did you understand it all?  More importantly, would your students?  Most students I meet don't understand it all, and that's a problem when it breaks and they are trying to fix things.  The truth is there is nothing complicated going on here--it's actually pretty basic stuff when you know how gcc and your tool-chain work.

As a student I was never taught how gcc and friends work.  I was taught C and C++, but never the tools you use to work with these languages.  No one ever taught me gcc, gdb, make, etc--I taught myself.  It's not how I would have done it, and not how I do it now as a prof.

Because my students have to work with gcc in complicated and interesting ways working on Mozilla, I'm always on the look-out for good resources that I can recommend to them.  Recently, I found a great one in Brian Gough's excellent book, An Introduction to GCC for the GNU Compilers gcc and g++ (you can also buy it online here, which I did to show my support).

The book is quite beautiful, in a K&R sort of way, with nice typesetting, uncluttered pages, and an accessible length of 137 pages.  Within the first 40 pages, he's explained everything that's happening above, and lots more.  And he does it in the most reassuring tone: there's nothing here you can't understand, let me show you.

I find students are often amazed at how usable Linux and the GNU tools really are, once they understand some of the underlying design choices and architecture.  Books like this one underscore how these tools aren't trying to be hard, and simply require a bit of work to get started.  I highly recommend this book.

Show Comments