You are previewing Advanced C and C++ Compiling.
O'Reilly logo
Advanced C and C++ Compiling

Book Description

Learning how to write C/C++ code is only the first step. To be a serious programmer, you need to understand the structure and purpose of the binary files produced by the compiler: object files, static libraries, shared libraries, and, of course, executables.

Advanced C and C++ Compiling explains the build process in detail and shows how to integrate code from other developers in the form of deployed libraries as well as how to resolve issues and potential mismatches between your own and external code trees.

With the proliferation of open source, understanding these issues is increasingly the responsibility of the individual programmer. Advanced C and C++ Compiling brings all of the information needed to move from intermediate to expert programmer together in one place -- an engineering guide on the topic of C/C++ binaries to help you get the most accurate and pertinent information in the quickest possible time.

What you'll learn

  • The details of the build process, including compiling and linking

  • The inner workings of static libraries, shared libraries, and executables

  • Ways to properly architect code for smooth integration of future changes

  • Tips for troubleshooting problems with compiling and linking as well as run-time problems

  • How to use operating system-specific (Linux and Windows) tools for analysis of binary files

  • Who this book is for

    C/C++ software designers aspiring to senior levels, software architects, build engineers, and Linux system administrators.

    Table of Contents

    1. Title Page
    2. Dedication
    3. Contents at a Glance
    4. Contents
    5. About the Author
    6. About the Technical Reviewers
    7. Acknowledgments
    8. Introduction
    9. CHAPTER 1: Multitasking OS Basics
      1. Useful Abstractions
      2. Memory Hierarchy and Caching Strategy
      3. Virtual Memory
      4. Virtual Addressing
      5. Process Memory Division Scheme
      6. The Roles of Binaries, Compiler, Linker, and Loader
      7. Summary
    10. CHAPTER 2: Simple Program Lifetime Stages
      1. Initial Assumptions
      2. Code Writing
      3. Compiling
      4. Linking
      5. Executable File Properties
    11. CHAPTER 3: Program Execution Stages
      1. Importance of the Shell
      2. Kernel Role
      3. Loader Role
      4. Executing Program Entry Point
    12. CHAPTER 4: The Impact of Reusing Concept
      1. Static Libraries
      2. Dynamic Libraries
      3. Static vs. Dynamic Libraries Comparison Points
      4. Useful Comparison Analogies
      5. The Conclusion: The Impact of Binary Reuse Concept
    13. CHAPTER 5: Working with Static Libraries
      1. Creating Static Library
      2. Using the Static Library
      3. Static Libraries Tips and Tricks
    14. CHAPTER 6: Designing Dynamic Libraries: Basics
      1. Creating the Dynamic Library
      2. Designing Dynamic Libraries
      3. Dynamic Linking Modes
    15. CHAPTER 7: Locating the Libraries
      1. Typical Library Use Case Scenarios
      2. Build Time Library Location Rules
      3. Runtime Dynamic Library Location Rules
      4. Linux Demo of Build Time and Runtime Conventions
    16. CHAPTER 8: Designing Dynamic Libraries: Advanced Topics
      1. Why Resolved Memory Addresses Are a Must
      2. General Problem of Resolving References
      3. Problems Caused by Address Translation
      4. Linker-Loader Coordination
      5. Linker-Loader Coordination Implementation Techniques
    17. CHAPTER 9: Handling Duplicate Symbols When Linking In Dynamic Libraries
      1. Duplicate Symbols Definition
      2. Duplicate Symbols Default Handling
      3. Duplicate Symbols Handling When Linking in Dynamic Libraries
      4. Analyses of Specific Duplicate Names Cases
      5. Final Remark: Linking Does Not Provide Any Kind of Namespace Inheritance
    18. CHAPTER 10: Dynamic Libraries Versioning
      1. Gradation of Versions and their Impact on Backwards Compatibility
      2. Linux Dynamic Library Versioning Schemes
      3. Windows Dynamic Libraries Versioning
    19. CHAPTER 11: Dynamic Libraries: Miscellaneous Topics
      1. Plug-in Concept
      2. Tips and Tricks
    20. CHAPTER 12: Linux Toolbox
      1. Quick Insight Tools
      2. Detailed Analysis Tools
      3. Deployment Phase Tools
      4. Runtime Analysis Tools
      5. Static Library Tools
    21. CHAPTER 13: Linux How To’s
      1. Debugging the Linking
      2. Determining the Binary File Type
      3. Determining the Binary File Entry Point
      4. List Symbols
      5. List and Examine Sections
      6. List and Examine Segments
      7. Disassembling the Code
      8. Identifying the Debug Build
      9. Listing Load-time Dependencies
      10. Listing the Libraries Known to the Loader
      11. Listing Dynamically Linked Libraries
      12. Creating and Maintaining the Static Library
    22. CHAPTER 14: Windows Toolbox
      1. Library Manager (lib.exe)
      2. dumpbin Utility
      3. Dependency Walker
    23. Index