Index
[]abstract base classesaccessaddingalgorithmscontainersrangessequencesapplicationsbuildingobtainingapplyingargumentsarithmetic operationsattributes
Index
[]binary filesdirectoriesfilesbuffersbuildingapplications
Index
[]calculatingcalendarscase-insensitive stringscharactersstringsclassesfunctionsmember variablesobjectsoperatorsstreamscodecommandscomparingcompilingcomplex applicationscomputingconfiguringconstructorscontainersobjectsvectorsconvertingstringscopyingcountingcreating [See configuring]Cygwin
Index
[]datesdeclaringdefiningdeletingDev-C++directoriessymbolsDocument Object Model [See DOM]Document Type Definition [See DTD]documentsXMLdynamic librariesdynamic link libraries [See DLLs]
Index
[]elementscontainersrangesenvironment variablesexceptionsclassesexportingexpressionsExtensible Markup Language [See XML]extractingfilenames
Index
[]filenamesfilesbinarydirectoriesflagsformattingclassesnumbersfunctionsmember [See member functions]objects
Index
[]generatingGNU Complier Collection [See GCC]groups
Index
[]headersHello World
Index
[]implementingimportinginitializinginstallinginstancesinstantiationintegersIntegrated Development Environments [See IDEs]internationalizationiteratorscontainers
Index
[]
Index
[]
Index
[]lengthlibrariesstatic [See static libraries]lineslinkinglistslocaleslocks
Index
[]macrosmanagementcontainersvectorsmanipulatorsmatriciesmember functionsmember variablesmemorymethodsMicrosoft Windows [See Windows]money [See currency, reading and writing]multithreading
Index
[]namesfilenamesnamespacesnodesnotificationnumbersrandomstringsnumeric types
Index
[]objectsfunctionsobtainingoperatorsoptionsoutputoverloadingoperators
Index
[]parsingpassingpathspatterns[See also optimizing vectors]pointersprinting
Index
[]
Index
[]random numbersrangesreadingresizingresourcesrulesruntime
Index
[]safetySAX2 ContentHandlersequencesstringsserializationsetssizingsortingstatisticsstoringstreamsclassescase-insensitivenumbersstructs (tm)substringssymbols
Index
[]
Index
[][See also documents]threadstimetm structstoolstransformingtypesnumeric
Index
[]Unixuppercase
Index
[]validatingXML documentsvaluesvariablesenvironmentmembervariantsvectorsvisibility
Index
[]whitespaceWindowswriting
Index
[]XercesXML (Extensible Markup Language)validating
Index
[]
Index
[]
Introduction to Building
This chapter contains recipes for transforming C++ source code intoexecutable programs and libraries. By working through these recipes,you'll learn about the basic tools used to build C++applications, the various types of binary files involved in the buildprocess, and the systems that have been developed to make buildingC++ applications manageable.
If you look at the titles of the recipes in this chapter, you mightget the impression that I solve the same problems over and overagain. You'd be right. That'sbecause there are many ways to build C++ applications, and while Ican't cover them all, I try to cover some of themost important methods. In the first dozen or so recipes, I show howto accomplish three fundamental tasksbuilding staticlibraries, building dynamic libraries, and buildingexecutablesusing a variety of methods. The recipes are groupedby method: first, I look at building from the command line, then withthe Boost build system (Boost.Build), and thenwith anIntegratedDevelopment Environment (IDE), and finally with GNUmake.
Before you start reading recipes, be sure to read the followingintroductory sections. I'll explain some basicterminology, provide an overview of the command-line tools, buildsystems and IDEs covered in the chapter, and introduce the sourcecode examples.
![Picture 1](/uploads/posts/book/25609/tip_yellow.jpg) | Even if you'll be using a build system or IDE, youshould start by reading the recipes on building from the commandline: these recipes introduce some essential concepts thatyou'll need to understand later in this chapter. |
|
Basic Terminology
The three basic toolsusedto build C++ applications are thecompiler,thelinker,and thearchiver(orlibrarian).A collection of these programs and possibly other tools is called atoolset.
The compiler takes C++ source files as input and producesobjectfiles,which contain a mixture of machine-executable code and symbolicreferences to functions and data. The archiver takes a collection ofobject files as input and produces a staticlibrary, orarchive,which is simply a collection of object files grouped for convenientuse. The linker takes a collection of object files and libraries andresolves their symbolic references to produceeither anexecutable or dynamiclibrary.Roughly speaking, the linker operates by matching each use of asymbol to its definition. When an executable or dynamic library iscreated, it is said to be linked; the librariesused to build the executable or dynamic library are said to belinked against.
An executable, or application, issimply any program that can be executed bythe operating system. A dynamic library, also called ashared library, is like an executable except that itcan'tbe run on its own; it consists of a body of machine-executable codethat is loaded into memory after an application is started and can beshared by one or more applications. On Windows, dynamic libraries arealso called dynamic linklibraries (DLLs).
The object files and static libraries on which an executable dependsare needed only when the executable is built. The dynamic librarieson which an executable depends, however, must be present on auser's system when the executable is run.
shows the file extensions typicallyassociated with these four basic types of files on Microsoft Windowsand Unix. When I mention a file that has a different extension onWindows and Unix, I'll sometimes omit the extensionif it's clear from the context.
Table 1-1. File extensions on Windows and Unix
File type | Windows | Mac OS X | Other Unix |
---|
Object files | .obj | .o | .o |
Static libraries | .lib | .a | .a |
Dynamic libraries | .dll | .dylib | .so |
Executables | .exe | No extension | No extension |
![Picture 2](/uploads/posts/book/25609/tip_yellow.jpg) | In this chapter, whenever I say Unix, I mean Linux, too. |
|
![Picture 3](/uploads/posts/book/25609/tip_yellow.jpg) | When you build the examples in this chapter, your tools will generatea number of auxiliary files with extensions thatdon't appear in . UnlessI mention otherwise, you can safely ignore these files. If you reallywant to know what they do, consult your toolset'sdocumentation. |
|
IDEs and Build Systems
Thecompiler, linker, and archiver are