1. Trang chủ
  2. » Công Nghệ Thông Tin

Syd logan cross platform development in c++

575 623 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 575
Dung lượng 4,23 MB

Nội dung

Đây là quyển sách tiếng anh về lĩnh vực công nghệ thông tin cho sinh viên và những ai có đam mê. Quyển sách này trình về lý thuyết ,phương pháp lập trình cho ngôn ngữ C và C++.

www.dbebooks.com - Free Books & magazines Cross-Platform Development in C++ = This page intentionally left blank = Cross-Platform Development in C++ Building Mac OS X, Linux, and Windows Applications Syd Logan 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.informit.com/title/9780321246424 and www.crossplatformbook.com Library of Congress Cataloging-in-Publication Data: Logan, Syd. Cross-platform development in C++ : building Mac OS X, Linux, and Windows applications / Syd Logan. p. cm. ISBN 0-321-24642-X (pbk. : alk. paper) 1. Cross-platform software development. 2. C++ (Computer program language) I. Title. QA76.76.D47L65 2007 005.13’3 dc22 2007036292 Copyright © 2008 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 501 Boylston Street, Suite 900 Boston, MA 02116 Fax: (617) 671-3447 ISBN-13: 978-0-321-24642-4 ISBN-10: 0-321-24642-X Text printed in the United States on recycled paper at RR Donnelly in Crawfordsville, Indiana. First printing December 2007 Editor-in-Chief Mark Taub Acquisitions Editor Greg Doench Development Editor Michael Thurston Managing Editor Gina Kanouse Project Editor Anne Goebel Copy Editor Keith Cline Indexer Erika Millen Proofreader Kathy Ruiz Technical Reviewers Jim Dunn Amy Fong Hang Lau Stephen Morse Lew Pitcher Sean Su Namachivayam Thirumazshusai Doug Turner Roy Yokohama Publishing Coordinator Andrea Bledsoe Cover Designer Gary Adair Composition Nonie Ratcliff This book is dedicated to all of the members of Netscape CPD and Mozilla, from whom I have learned so much. It was truly an honor to be a part of the team. = This page intentionally left blank Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Areas That Can Affect Software Portability . . . . . . . . . . . . . . . . . . . 3 The Role of Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1 Policy and Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Item 1: Make All of Your Platforms a Priority . . . . . . . . . . . . . . . . . 17 Item 2: Code from a Common Codebase . . . . . . . . . . . . . . . . . . . . 22 Platform Factory Implementations . . . . . . . . . . . . . . . . . . . . . . . 29 Implementation Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Platform-Specific ProcessesImpl Classes . . . . . . . . . . . . . . . . . . . 32 Creating the Instance Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . 42 Organizing the Project in CVS or SVN . . . . . . . . . . . . . . . . . . . 45 Makefiles and Building the Code . . . . . . . . . . . . . . . . . . . . . . . . . 49 Item 3: Require Developers to Compile Their Code with Different Compilers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Item 4: Require Developers to Build Their Code on Multiple Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Item 5: Test Builds on Each Supported Platform . . . . . . . . . . . . . . . 60 Item 6: Pay Attention to Compiler Warnings . . . . . . . . . . . . . . . . . . 61 GNU Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Microsoft Visual C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Contents vii = 2 Build System/Toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Item 7: Use Whatever Compiler Makes the Most Sense for a Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Item 8: Use Native IDEs When Appropriate . . . . . . . . . . . . . . . . . . 67 Item 9: Install and Use Cygwin on Windows . . . . . . . . . . . . . . . . . . 71 Item 10: Use a Cross-Platform Make System . . . . . . . . . . . . . . . . . . 76 Make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Building on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Autoconf/Automake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Imake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Installing on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Installing on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Using Imake, an Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Imakefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Building a Complete Program from Multiple Sources . . . . . . . . . 95 Overriding Defaults with site.def . . . . . . . . . . . . . . . . . . . . . . . . 99 Eliminating #ifdefs in Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Files Used by Imake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Building Projects with Subdirectories . . . . . . . . . . . . . . . . . . . . 108 Building Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 3 Software Configuration Management . . . . . . . . . . . . . . . . . . 131 Item 11: Use a Cross-Platform Bug Reporting and Tracking System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Ability to Track Platform-Specific Bugs . . . . . . . . . . . . . . . . . . 133 Bugzilla . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Item 12: Set Up a Tinderbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Item 13: Use CVS or Subversion to Manage Source Code . . . . . . . 147 Setting Up and Using CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Item 14: Use Patch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Patch Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Dealing with Rejects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Patch and Cross-Platform Development . . . . . . . . . . . . . . . . . . 163 viii Contents 4 Installation and Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Item 15: Provide Support for Native Installers . . . . . . . . . . . . . . . 165 XPInstall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Platform Installs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 5 Operating System Interfaces and Libraries . . . . . . . . . . . . . . . 221 Item 16: Use Standards-Based APIs (For Example, POSIX) . . . . . . 222 POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 Support for POSIX, SVID, XPG, and BSD . . . . . . . . . . . . . . . 226 Using Standards Support in GCC . . . . . . . . . . . . . . . . . . . . . . . 227 Microsoft Runtime Library Support for POSIX . . . . . . . . . . . . 231 Using GCC on Microsoft Windows . . . . . . . . . . . . . . . . . . . . . 234 Deciding Which Standards to Support . . . . . . . . . . . . . . . . . . . 240 Item 17: Consider Using a Platform Abstraction Library Such as NSPR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 Why NSPR? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 NSPR Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 Additional NSPR Functionality . . . . . . . . . . . . . . . . . . . . . . . . 260 6 Miscellaneous Portability Topics . . . . . . . . . . . . . . . . . . . . . . . 273 Item 18: Take Care When Using Floating Point . . . . . . . . . . . . . . . 274 Don’t Serialize Floating-Point Values as Binary . . . . . . . . . . . . 276 Equality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Item 19: Be Explicit Regarding the Sign of Char Types . . . . . . . . . 278 Item 20: Avoid the Serialization of Binary Data . . . . . . . . . . . . . . 280 Item 21: Avoid Problems Related to the Size and Organization of Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 Size of Integer Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 NSPR and Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Sizes and Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 Integer Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 Struct Alignment and Ordering . . . . . . . . . . . . . . . . . . . . . . . . . 299 7 User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 Item 22: Separate the User Interface from the Model . . . . . . . . . . 304 Separating the User Interface and Application Logic with Model/View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Contents ix [...]... Gecko continues to evolve and solve additional cross- platform challenges The recent addition of SVG native support marks yet another chapter in Gecko’s portability success The information Syd Logan is presenting here is the collective insight of the myriad engineers who ironed out the special problems associated with creating cross- platform production software Although it is written with C++ in mind, many... positions during the development of Netscape 6 and 7 After Netscape, Syd remained at AOL where he implemented VOIP and peer-to-peer video features as a member of the AOL Instant Messenger team Syd s previous publications include Developing Imaging Applications with XIELib and Gtk+ Programming in C, both published by Prentice Hall His technical interests include machine learning, operating systems design,... diverse set of platforms I worked on an embedded kernel of my own design for a somewhat obscure CPU (the TMS34020) I obtained experience in Windows kernel development, writing file systems drivers for the Windows NT and Windows 98 kernels, to support the development of a Network File System (NFS) client In user space, I mostly specialized in user interface development, initially developing Motif (Z-Mail)... recommend reading Items 22 and 23, and Chapter 8, “wxWidgets.” If you are interested in GUI toolkit internals, or plan to help out with the development of Trixul (described in the following section), you will definitely want to read Chapter 9, “Developing a Cross- Platform GUI Toolkit in C++. ” A Word about Trixul Trixul is an open source project that I put together specifically to aid me in the writing of this... you are interested in Qt, a few books are currently available that cover the subject in great detail, perhaps most notably C++ GUI Programming with Qt 4, by Jasmin Blanchette and Mark Summerfield, also published by Prentice Hall (see also their Qt 3-specific book) The last chapter of this book, Chapter 9, “Developing a Cross- Platform GUI Toolkit in C++, ” starts with an introduction to the cross- platform. .. with diverse graphical user interface environments I was given the opportunity to develop a strategy to solve the thorny cross- platform user interface problem I authored a document that described how to achieve a crossplatform user interface by combining an XML meta description of the user interface elements and JavaScript as control/event logic within the Gecko rendering engine This document was the... implementing the code In all, there are 23 items presented in these initial chapters The implementation of a user interface is a major concern in the development of cross- platform desktop applications Item 23 serves to introduce the topic The final two chapters of the book are therefore devoted to cross- platform GUI-related topics The first of these chapters Preface xix provides a comprehensive introduction... helped turn my manuscript into its final form, including Keith Kline who did much of the copyediting, Anne Goebel, and Gina Kanouse I am particularly grateful to Anne for her willingness to work with me through numerous “minor” changes I requested during the final review process There is no doubt in my mind that these requests caused her much extra work (not to mention pain upon receiving each new e-mail from... wxWidgets crossplatform GUI toolkit After reading my introduction to wxWidgets, you may want to check out Prentice Hall’s detailed treatment on the subject, Cross- Platform GUI Programming with wxWidgets, by Julian Smart, et al wxWidgets is not the only cross- platform GUI toolkit available for use in your projects Another capable, and very popular cross- platform GUI toolkit, Qt, is not covered in this... operating system Consider the following C++ code: #include using namespace std; int main( int argc, char *argv[]) { cout . Cataloging -in- Publication Data: Logan, Syd. Cross-platform development in C++ : building Mac OS X, Linux, and Windows applications / Syd Logan. p. cm. ISBN 0-3 2 1-2 4642-X. www.dbebooks.com - Free Books & magazines Cross-Platform Development in C++ = This page intentionally left blank = Cross-Platform Development in C++ Building Mac

Ngày đăng: 19/03/2014, 14:14

TỪ KHÓA LIÊN QUAN