| 1 | .. Copyright David Abrahams 2006. Distributed under the Boost |
|---|
| 2 | .. Software License, Version 1.0. (See accompanying |
|---|
| 3 | .. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 4 | |
|---|
| 5 | ======================================= |
|---|
| 6 | |(logo)|__ Getting Started on Windows |
|---|
| 7 | ======================================= |
|---|
| 8 | |
|---|
| 9 | .. |(logo)| image:: ../../boost.png |
|---|
| 10 | :alt: Boost |
|---|
| 11 | :class: boost-logo |
|---|
| 12 | |
|---|
| 13 | __ ../../index.htm |
|---|
| 14 | |
|---|
| 15 | .. section-numbering:: |
|---|
| 16 | |
|---|
| 17 | .. Admonition:: A note to Cygwin_ and MinGW_ users |
|---|
| 18 | |
|---|
| 19 | If you plan to use your tools from the Windows command prompt, |
|---|
| 20 | you're in the right place. If you plan to build from the Cygwin_ |
|---|
| 21 | bash shell, you're actually running on a POSIX platform and |
|---|
| 22 | should follow the instructions for `getting started on Unix |
|---|
| 23 | variants`_. Other command shells, such as MinGW_\ 's MSYS, are |
|---|
| 24 | not supported—they may or may not work. |
|---|
| 25 | |
|---|
| 26 | .. _`Getting Started on Unix Variants`: unix-variants.html |
|---|
| 27 | .. _Cygwin: http://www.cygwin.com |
|---|
| 28 | .. _MinGW: http://mingw.org |
|---|
| 29 | |
|---|
| 30 | .. Contents:: Index |
|---|
| 31 | |
|---|
| 32 | Get Boost |
|---|
| 33 | ========= |
|---|
| 34 | |
|---|
| 35 | The easiest way to get a copy of Boost is to use the `installer`_ |
|---|
| 36 | provided by `Boost Consulting`_. We especially recommend this |
|---|
| 37 | method if you use Microsoft Visual Studio .NET 2003 or Microsoft |
|---|
| 38 | Visual Studio 2005, because the installer can download and install |
|---|
| 39 | precompiled library binaries, saving you the trouble of building |
|---|
| 40 | them yourself. To complete this tutorial, you'll need to at least |
|---|
| 41 | install the Boost.Regex_ binaries when given the option. |
|---|
| 42 | |
|---|
| 43 | .. _installer: http://www.boost-consulting.com/download/windows |
|---|
| 44 | .. _Boost Consulting: http://www.boost-consulting.com |
|---|
| 45 | |
|---|
| 46 | If you're using an earlier version of Visual Studio or some other |
|---|
| 47 | compiler, or if you prefer to build everything yourself, you can |
|---|
| 48 | download |boost.exe|_ and run it to install a complete Boost |
|---|
| 49 | distribution. [#zip]_ |
|---|
| 50 | |
|---|
| 51 | .. |boost.exe| replace:: |boost_ver|\ ``.exe`` |
|---|
| 52 | |
|---|
| 53 | .. _`boost.exe`: `sf-download`_ |
|---|
| 54 | |
|---|
| 55 | .. include:: detail/distro.rst |
|---|
| 56 | |
|---|
| 57 | .. include:: detail/header-only.rst |
|---|
| 58 | |
|---|
| 59 | .. include:: detail/build-simple-head.rst |
|---|
| 60 | |
|---|
| 61 | .. _`command prompt`: |
|---|
| 62 | .. _`command-line tool`: |
|---|
| 63 | |
|---|
| 64 | .. Note:: To build the examples in this guide, you can use an |
|---|
| 65 | Integrated Development Environment (IDE) like Visual Studio, or |
|---|
| 66 | you can issue commands from the `command prompt`_. Since every |
|---|
| 67 | IDE and compiler has different options and Microsoft's are by |
|---|
| 68 | far the dominant compilers on Windows, we only give specific |
|---|
| 69 | directions here for Visual Studio 2005 and .NET 2003 IDEs and |
|---|
| 70 | their respective command prompt compilers (using the command |
|---|
| 71 | prompt is a bit simpler). If you are using another compiler or |
|---|
| 72 | IDE, it should be relatively easy to adapt these instructions to |
|---|
| 73 | your environment. |
|---|
| 74 | |
|---|
| 75 | .. sidebar:: Command Prompt Basics |
|---|
| 76 | :class: small |
|---|
| 77 | |
|---|
| 78 | In Windows, a command-line tool is invoked by typing its name, |
|---|
| 79 | optionally followed by arguments, into a *Command Prompt* window |
|---|
| 80 | and pressing the Return (or Enter) key. |
|---|
| 81 | |
|---|
| 82 | To open a generic *Command Prompt*, click the *Start* menu |
|---|
| 83 | button, click *Run*, type “cmd”, and then click *OK*. |
|---|
| 84 | |
|---|
| 85 | .. _current directory: |
|---|
| 86 | |
|---|
| 87 | All commands are executed within the context of a **current |
|---|
| 88 | directory** in the filesystem. To set the current directory, |
|---|
| 89 | type: |
|---|
| 90 | |
|---|
| 91 | .. parsed-literal:: |
|---|
| 92 | |
|---|
| 93 | cd *path*\ \\\ *to*\ \\\ *some*\ \\\ *directory* |
|---|
| 94 | |
|---|
| 95 | followed by Return. For example, |
|---|
| 96 | |
|---|
| 97 | .. parsed-literal:: |
|---|
| 98 | |
|---|
| 99 | cd |default-root| |
|---|
| 100 | |
|---|
| 101 | Long commands can be continued across several lines by typing a |
|---|
| 102 | caret (``^``) at the end of all but the last line. Some examples |
|---|
| 103 | on this page use that technique to save horizontal space. |
|---|
| 104 | |
|---|
| 105 | .. _vs-header-only: |
|---|
| 106 | |
|---|
| 107 | Build From the Visual Studio IDE |
|---|
| 108 | -------------------------------- |
|---|
| 109 | |
|---|
| 110 | * From Visual Studio's *File* menu, select *New* > *Project…* |
|---|
| 111 | * In the left-hand pane of the resulting *New Project* dialog, |
|---|
| 112 | select *Visual C++* > *Win32*. |
|---|
| 113 | * In the right-hand pane, select *Win32 Console Application* |
|---|
| 114 | (VS8.0) or *Win32 Console Project* (VS7.1). |
|---|
| 115 | * In the *name* field, enter “example” |
|---|
| 116 | * Right-click **example** in the *Solution Explorer* pane and |
|---|
| 117 | select *Properties* from the resulting pop-up menu |
|---|
| 118 | * In *Configuration Properties* > *C/C++* > *General* > *Additional Include |
|---|
| 119 | Directories*, enter the path to the Boost root directory, for example |
|---|
| 120 | |
|---|
| 121 | |default-root| |
|---|
| 122 | |
|---|
| 123 | * In *Configuration Properties* > *C/C++* > *Precompiled Headers*, change |
|---|
| 124 | *Use Precompiled Header (/Yu)* to *Not Using Precompiled |
|---|
| 125 | Headers*. [#pch]_ |
|---|
| 126 | * Replace the contents of the ``example.cpp`` generated by the IDE |
|---|
| 127 | with the example code above. |
|---|
| 128 | * From the *Build* menu, select *Build Solution*. |
|---|
| 129 | |
|---|
| 130 | To test your application, hit the F5 key and type the following |
|---|
| 131 | into the resulting window, followed by the Return key:: |
|---|
| 132 | |
|---|
| 133 | 1 2 3 |
|---|
| 134 | |
|---|
| 135 | Then hold down the control key and press "Z", followed by the |
|---|
| 136 | Return key. |
|---|
| 137 | |
|---|
| 138 | |next|__ |
|---|
| 139 | |
|---|
| 140 | __ `Errors and Warnings`_ |
|---|
| 141 | |
|---|
| 142 | Or, Build From the Command Prompt |
|---|
| 143 | --------------------------------- |
|---|
| 144 | |
|---|
| 145 | From your computer's *Start* menu, if you are a Visual |
|---|
| 146 | Studio 2005 user, select |
|---|
| 147 | |
|---|
| 148 | *All Programs* > *Microsoft Visual Studio 2005* |
|---|
| 149 | > *Visual Studio Tools* > *Visual Studio 2005 Command Prompt* |
|---|
| 150 | |
|---|
| 151 | or, if you're a Visual Studio .NET 2003 user, select |
|---|
| 152 | |
|---|
| 153 | *All Programs* > *Microsoft Visual Studio .NET 2003* |
|---|
| 154 | > *Visual Studio .NET Tools* > *Visual Studio .NET 2003 Command Prompt* |
|---|
| 155 | |
|---|
| 156 | to bring up a special `command prompt`_ window set up for the |
|---|
| 157 | Visual Studio compiler. In that window, set the `current |
|---|
| 158 | directory`_ to a suitable location for creating some temporary |
|---|
| 159 | files and type the following command followed by the Return key: |
|---|
| 160 | |
|---|
| 161 | .. parsed-literal:: |
|---|
| 162 | |
|---|
| 163 | cl /EHsc /I |root| *path*\ \\\ *to*\ \\example.cpp |
|---|
| 164 | |
|---|
| 165 | To test the result, type: |
|---|
| 166 | |
|---|
| 167 | .. parsed-literal:: |
|---|
| 168 | |
|---|
| 169 | echo 1 2 3 | example |
|---|
| 170 | |
|---|
| 171 | .. include:: detail/errors-and-warnings.rst |
|---|
| 172 | |
|---|
| 173 | .. include:: detail/binary-head.rst |
|---|
| 174 | |
|---|
| 175 | Install Visual Studio (2005 or .NET 2003) Binaries |
|---|
| 176 | -------------------------------------------------- |
|---|
| 177 | |
|---|
| 178 | The installer_ supplied by Boost Consulting will download and |
|---|
| 179 | install pre-compiled binaries into the ``lib\`` subdirectory of the |
|---|
| 180 | boost root, typically |default-root|\ ``\lib\``. If you installed |
|---|
| 181 | all variants of the Boost.Regex_ binary, you're done with this |
|---|
| 182 | step. Otherwise, please run the installer again and install them |
|---|
| 183 | now. |
|---|
| 184 | |
|---|
| 185 | |next|__ |
|---|
| 186 | |
|---|
| 187 | __ `Link Your Program to a Boost Library`_ |
|---|
| 188 | |
|---|
| 189 | Or, Build Binaries From Source |
|---|
| 190 | ------------------------------ |
|---|
| 191 | |
|---|
| 192 | If you're using an earlier version of Visual C++, or a compiler |
|---|
| 193 | from another vendor, you'll need to use Boost.Build_ to create your |
|---|
| 194 | own binaries. |
|---|
| 195 | |
|---|
| 196 | .. include:: detail/build-from-source-head.rst |
|---|
| 197 | |
|---|
| 198 | For example, your session might look like this: [#continuation]_ |
|---|
| 199 | |
|---|
| 200 | .. parsed-literal:: |
|---|
| 201 | |
|---|
| 202 | C:\\WINDOWS> cd |default-root| |
|---|
| 203 | |default-root|> bjam **^** |
|---|
| 204 | More? **--build-dir=**\ C:\\temp\\build-boost **^** |
|---|
| 205 | More? **--toolset=**\ msvc stage |
|---|
| 206 | |
|---|
| 207 | .. include:: detail/build-from-source-tail.rst |
|---|
| 208 | |
|---|
| 209 | .. _auto-linking: |
|---|
| 210 | |
|---|
| 211 | .. include:: detail/link-head.rst |
|---|
| 212 | |
|---|
| 213 | .. Admonition:: Auto-Linking |
|---|
| 214 | |
|---|
| 215 | Most Windows compilers and linkers have so-called “auto-linking |
|---|
| 216 | support,” which eliminates the second challenge. Special code in |
|---|
| 217 | Boost header files detects your compiler options and uses that |
|---|
| 218 | information to encode the name of the correct library into your |
|---|
| 219 | object files; the linker selects the library with that name from |
|---|
| 220 | the directories you've told it to search. |
|---|
| 221 | |
|---|
| 222 | The GCC toolchains (Cygwin and MinGW) are notable exceptions; |
|---|
| 223 | GCC users should refer to the `linking instructions for Unix |
|---|
| 224 | variant OSes`__ for the appropriate command-line options to use. |
|---|
| 225 | |
|---|
| 226 | __ unix-variants.html#link-your-program-to-a-boost-library |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | Link From Within the Visual Studio IDE |
|---|
| 230 | -------------------------------------- |
|---|
| 231 | |
|---|
| 232 | Starting with the `header-only example project`__ we created |
|---|
| 233 | earlier: |
|---|
| 234 | |
|---|
| 235 | __ vs-header-only_ |
|---|
| 236 | |
|---|
| 237 | 1. Right-click **example** in the *Solution Explorer* pane and |
|---|
| 238 | select *Properties* from the resulting pop-up menu |
|---|
| 239 | 2. In *Configuration Properties* > *Linker* > *Additional Library |
|---|
| 240 | Directories*, enter the path to the Boost binaries, |
|---|
| 241 | e.g. |default-root|\ ``\lib\``. |
|---|
| 242 | 3. From the *Build* menu, select *Build Solution*. |
|---|
| 243 | |
|---|
| 244 | |next|__ |
|---|
| 245 | |
|---|
| 246 | __ `Test Your Program`_ |
|---|
| 247 | |
|---|
| 248 | Or, Link From the Command Prompt |
|---|
| 249 | -------------------------------- |
|---|
| 250 | |
|---|
| 251 | For example, we can compile and link the above program from the |
|---|
| 252 | Visual C++ command-line by simply adding the **bold** text below to |
|---|
| 253 | the command line we used earlier, assuming your Boost binaries are |
|---|
| 254 | in |default-root|\ ``\lib``: |
|---|
| 255 | |
|---|
| 256 | .. parsed-literal:: |
|---|
| 257 | |
|---|
| 258 | cl /EHsc /I |root| example.cpp **^** |
|---|
| 259 | **/link /LIBPATH:** |default-root-bold|\ **\\lib** |
|---|
| 260 | |
|---|
| 261 | Library Naming |
|---|
| 262 | -------------- |
|---|
| 263 | |
|---|
| 264 | .. Note:: If, like Visual C++, your compiler supports auto-linking, |
|---|
| 265 | you can probably |next|__. |
|---|
| 266 | |
|---|
| 267 | __ `Test Your Program`_ |
|---|
| 268 | |
|---|
| 269 | .. include:: detail/library-naming.rst |
|---|
| 270 | |
|---|
| 271 | .. include:: detail/test-head.rst |
|---|
| 272 | |
|---|
| 273 | Now, in a `command prompt`_ window, type: |
|---|
| 274 | |
|---|
| 275 | .. parsed-literal:: |
|---|
| 276 | |
|---|
| 277 | *path*\ \\\ *to*\ \\\ *compiled*\ \\example < *path*\ \\\ *to*\ \\\ jayne.txt |
|---|
| 278 | |
|---|
| 279 | The program should respond with the email subject, “Will Success |
|---|
| 280 | Spoil Rock Hunter?” |
|---|
| 281 | |
|---|
| 282 | .. include:: detail/conclusion.rst |
|---|
| 283 | |
|---|
| 284 | ------------------------------ |
|---|
| 285 | |
|---|
| 286 | .. [#zip] If you prefer not to download executable programs, |
|---|
| 287 | download |boost.zip|_ and use an external tool to decompress |
|---|
| 288 | it. We don't recommend using Windows' built-in decompression as |
|---|
| 289 | it can be painfully slow for large archives. |
|---|
| 290 | |
|---|
| 291 | .. [#installer-src] If you used the installer_ from Boost |
|---|
| 292 | Consulting and deselected “Source and Documentation” (it's |
|---|
| 293 | selected by default), you won't see the ``libs/`` subdirectory. |
|---|
| 294 | That won't affect your ability to use precompiled binaries, but |
|---|
| 295 | you won't be able to rebuild libraries from scratch. |
|---|
| 296 | |
|---|
| 297 | .. [#pch] There's no problem using Boost with precompiled headers; |
|---|
| 298 | these instructions merely avoid precompiled headers because it |
|---|
| 299 | would require Visual Studio-specific changes to the source code |
|---|
| 300 | used in the examples. |
|---|
| 301 | |
|---|
| 302 | .. [#continuation] In this example, the caret character ``^`` is a |
|---|
| 303 | way of continuing the command on multiple lines. The command |
|---|
| 304 | prompt responds with ``More?`` to prompt for more input. Feel |
|---|
| 305 | free to omit the carets and subsequent newlines; we used them so |
|---|
| 306 | the example would fit on a page of reasonable width. |
|---|
| 307 | |
|---|
| 308 | .. |boost.zip| replace:: |boost_ver|\ ``.zip`` |
|---|
| 309 | |
|---|
| 310 | .. _`boost.zip`: `sf-download`_ |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | .. include:: detail/common-footnotes.rst |
|---|
| 314 | .. include:: detail/release-variables.rst |
|---|
| 315 | .. include:: detail/common-windows.rst |
|---|
| 316 | .. include:: detail/links.rst |
|---|