The Linux Programmer's Toolbox.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
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 1 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 trade- marks. 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 war- ranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or con- sequential 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 [email protected] For sales outside the United States, please contact: International Sales [email protected] 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) 1. Linux. 2. 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 per- mission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval sys- tem, 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 1 Downloading and Installing Open Source Tools . 1 1.1 Introduction . 1 1.2 What Is Open Source? . 2 1.3 What Does Open Source Mean to You? . 2 1.3.1 Finding Tools . 3 1.3.2 Distribution Formats . 4 1.4 An Introduction to Archive Files . 4 1.4.1 Identifying Archive Files . 6 1.4.2 Querying an Archive File . 7 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 2 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 ix Chapter 3 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 . ..