The Linux Programmer’s Toolbox Prentice Hall Open Source Software Development Series Arnold Robbins, Series Editor “Real world code from real world applications” Open Source technology has revolutionized the computing world Many large-scale projects are in production use worldwide, such as Apache, MySQL, and Postgres, with programmers writing applications in a variety of languages including Perl, Python, and PHP These technologies are in use on many different systems, ranging from proprietary systems, to Linux systems, to traditional UNIX systems, to mainframes The Prentice Hall Open Source Software Development Series is designed to bring you the best of these Open Source technologies Not only will you learn how to use them for your projects, but you will learn from them By seeing real code from real applications, you will learn the best practices of Open Source developers the world over Titles currently in the series include: Linux® Debugging and Performance Tuning: Tips and Techniques Steve Best 0131492470, Paper, ©2006 Understanding AJAX: Using JavaScript to Create Rich Internet Applications Joshua Eichorn 0132216353, Paper, ©2007 Embedded Linux Primer Christopher Hallinan 0131679848, Paper, ©2007 SELinux by Example Frank Mayer, David Caplan, Karl MacMillan 0131963694, Paper, â2007 UNIX to Linuxđ Porting Alfredo Mendoza, Chakarat Skawratananond, Artis Walker 0131871099, Paper, ©2006 Linux Programming by Example: The Fundamentals Arnold Robbins 0131429647, Paper, â2004 The Linuxđ Kernel Primer: A Top-Down Approach for x86 and PowerPC Architectures Claudia Salzberg, Gordon Fischer, Steven Smolski 0131181637, Paper, ©2006 OSD_Series_7x9_25.indd 6/27/06 5:44:08 PM The Linux Programmer’s Toolbox John Fusco Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests For more information, please contact: U.S Corporate and Government Sales (800) 382-3419 corpsales@pearsontechgroup.com For sales outside the United States, please contact: International Sales international@pearsoned.com Visit us on the Web: www.prenhallprofessional.com Library of Congress Cataloging-in-Publication Data Fusco, John The Linux programmer’s toolbox / John Fusco p cm Includes bibliographical references and index ISBN 0-13-219857-6 (pbk : alk paper) Linux Operating systems (Computers) I Title QA76.76.O63F875 2007 005.4'32—dc22 2006039343 Copyright © 2007 Pearson Education, Inc All rights reserved Printed in the United States of America This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise For information regarding permissions, write to: Pearson Education, Inc Rights and Contracts Department One Lake Street Upper Saddle River, NJ 07458 Fax: (201) 236-3290 ISBN 0-13-219857-6 Text printed in the United States on recycled paper at Courier in Stoughton, Massachusetts First printing, March 2007 To my wife, Lisa, and my children, Andrew, Alex, and Samantha This page intentionally left blank Contents Foreword xvii Preface xix Acknowledgments xxiii About the Author xxv Chapter Downloading and Installing Open Source Tools 1.1 Introduction 1.2 What Is Open Source? 1.3 What Does Open Source Mean to You? 1.3.1 Finding Tools 1.3.2 Distribution Formats 1.4 An Introduction to Archive Files 1.4.1 Identifying Archive Files 1.4.2 Querying an Archive File 1.4.3 Extracting Files from an Archive File 11 1.5 Know Your Package Manager 12 1.5.1 Choosing Source or Binary 14 1.5.2 Working with Packages 16 1.6 Some Words about Security and Packages 17 1.6.1 The Need for Authentication 19 1.6.2 Basic Package Authentication 19 1.6.3 Package Authentication with Digital Signatures 21 1.6.4 GPG Signatures with RPM 22 1.6.5 When You Can’t Authenticate a Package 25 vii viii Contents 1.7 Inspecting Package Contents 27 1.7.1 How to Inspect Packages 28 1.7.2 A Closer Look at RPM Packages 30 1.7.3 A Closer Look at Debian Packages 31 1.8 Keeping Packages up to Date 33 1.8.1 Apt: Advanced Package Tool 34 1.8.2 Yum: Yellowdog Updater Modified 35 1.8.3 Synaptic: The GUI Front End for APT 36 1.8.4 up2date: The Red Hat Package Updater 37 1.9 Summary 39 1.9.1 Tools Used in This Chapter 39 1.9.2 Online References 40 Chapter Building from Source 41 2.1 Introduction 41 2.2 Build Tools 41 2.2.1 Background 42 2.2.2 Understanding make 44 2.2.3 How Programs Are Linked 67 2.2.4 Understanding Libraries 69 2.3 The Build Process 74 2.3.1 The GNU Build Tools 74 2.3.2 The configure Stage 74 2.3.3 The Build Stage: make 77 2.3.4 The Install Stage: make install 78 2.4 Understanding Errors and Warnings 78 2.4.1 Common Makefile Mistakes 79 2.4.2 Errors during the configure Stage 82 2.4.3 Errors during the Build Stage 83 2.4.4 Understanding Compiler Errors 86 2.4.5 Understanding Compiler Warnings 88 2.4.6 Understanding Linker Errors 98 2.5 Summary 100 2.5.1 Tools Used in This Chapter 101 2.5.2 Online References 101 Contents Chapter ix Finding Help 103 3.1 Introduction 103 3.2 Online Help Tools 103 3.2.1 The man Page 104 3.2.2 man Organization 105 3.2.3 Searching the man Pages: apropos 107 3.2.4 Getting the Right man Page: whatis 110 3.2.5 Things to Look for in the man Page 111 3.2.6 Some Recommended man Pages 112 3.2.7 GNU info 115 3.2.8 Viewing info Pages 115 3.2.9 Searching info Pages 118 3.2.10 Recommended info Pages 119 3.2.11 Desktop Help Tools 120 3.3 Other Places to Look 120 3.3.1 /usr/share/doc 121 3.3.2 Cross Referencing and Indexing 121 3.3.3 Package Queries 122 3.4 Documentation Formats 124 3.4.1 TeX/LaTeX/DVI 124 3.4.2 Texinfo 125 3.4.3 DocBook 126 3.4.4 HTML 127 3.4.5 PostScript 129 3.4.6 Portable Document Format (PDF) 130 3.4.7 troff 131 3.5 Internet Sources of Information 131 3.5.1 www.gnu.org 131 3.5.2 SourceForge.net 132 3.5.3 The Linux Documentation Project 133 3.5.4 Usenet 134 3.5.5 Mailing Lists 134 3.5.6 Other Forums 134 3.6 Finding Information about the Linux Kernel 134 3.6.1 The Kernel Build 135 3.6.2 Kernel Modules 137 ... or other documentation stitched into the text The GNU and Linux developers have done a great xix xx Preface job of documenting their work, but that documentation can be hard to find for the inexperienced... understanding of the Linux programming environment If you’re an experienced Windows programmer who feels like a fish out of water in the Linux environment, then this book is for you, too Non -programmers. .. the best of these Open Source technologies Not only will you learn how to use them for your projects, but you will learn from them By seeing real code from real applications, you will learn the