unix-variants.rst 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. |(logo)|__ Getting Started on Unix Variants
  6. =============================================
  7. .. meta::
  8. :description: Getting Started with Boost on Unix Variants (including Linux and MacOS)
  9. .. |(logo)| image:: ../../boost.png
  10. :alt: Boost
  11. :class: boost-logo
  12. __ ../../index.htm
  13. .. section-numbering::
  14. .. maybe we don't need this
  15. .. Admonition:: A note to Cygwin_ and MinGW_ users
  16. If you plan to build from the Cygwin_ bash shell, you're in the
  17. right place. If you plan to use your tools from the Windows
  18. command prompt, you should follow the instructions for `getting
  19. started on Windows`_. Other command shells, such as MinGW_\ 's
  20. MSYS, are not supported—they may or may not work.
  21. .. _`Getting Started on Windows`: windows.html
  22. .. _Cygwin: http://www.cygwin.com
  23. .. _MinGW: http://mingw.org
  24. .. Contents:: Index
  25. Get Boost
  26. =========
  27. The most reliable way to get a copy of Boost is to download a
  28. distribution from SourceForge_:
  29. .. _SourceForge: `sf-download`_
  30. 1. Download |boost.tar.bz2|_.
  31. 2. In the directory where you want to put the Boost installation,
  32. execute
  33. .. parsed-literal::
  34. tar --bzip2 -xf */path/to/*\ |boost_ver|\ .tar.bz2
  35. .. |boost.tar.bz2| replace:: |boost_ver|\ ``.tar.bz2``
  36. .. _`boost.tar.bz2`: `sf-download`_
  37. .. Admonition:: Other Packages
  38. RedHat, Debian, and other distribution packagers supply Boost
  39. library packages, however you may need to adapt these
  40. instructions if you use third-party packages, because their
  41. creators usually choose to break Boost up into several packages,
  42. reorganize the directory structure of the Boost distribution,
  43. and/or rename the library binaries. [#packagers]_ If you have
  44. any trouble, we suggest using an official Boost distribution
  45. from SourceForge_.
  46. .. include:: detail/distro.rst
  47. .. include:: detail/header-only.rst
  48. .. include:: detail/build-simple-head.rst
  49. Now, in the directory where you saved ``example.cpp``, issue the
  50. following command:
  51. .. parsed-literal::
  52. c++ -I |root| example.cpp -o example
  53. To test the result, type:
  54. .. parsed-literal::
  55. echo 1 2 3 | ./example
  56. .. include:: detail/errors-and-warnings.rst
  57. .. include:: detail/binary-head.rst
  58. Easy Build and Install
  59. ----------------------
  60. Issue the following commands in the shell (don't type ``$``; that
  61. represents the shell's prompt):
  62. .. parsed-literal::
  63. **$** cd |root|
  64. **$** ./bootstrap.sh --help
  65. Select your configuration options and invoke ``./bootstrap.sh`` again
  66. without the ``--help`` option. Unless you have write permission in
  67. your system's ``/usr/local/`` directory, you'll probably want to at
  68. least use
  69. .. parsed-literal::
  70. **$** ./bootstrap.sh **--prefix=**\ *path*\ /\ *to*\ /\ *installation*\ /\ *prefix*
  71. to install somewhere else. Also, consider using the
  72. ``--show-libraries`` and ``--with-``\ *library_name* options to limit the
  73. long wait you'll experience if you build everything. Finally,
  74. .. parsed-literal::
  75. **$** ./bjam install
  76. will leave Boost binaries in the ``lib/`` subdirectory of your
  77. installation prefix. You will also find a copy of the Boost
  78. headers in the ``include/`` subdirectory of the installation
  79. prefix, so you can henceforth use that directory as an ``#include``
  80. path in place of the Boost root directory.
  81. |next|__
  82. __ `Link Your Program to a Boost Library`_
  83. Or, Build Custom Binaries
  84. -------------------------
  85. If you're using a compiler other than your system's default, you'll
  86. need to use Boost.Build_ to create binaries.
  87. You'll also
  88. use this method if you need a nonstandard build variant (see the
  89. `Boost.Build documentation`_ for more details).
  90. .. Admonition:: Boost.CMake
  91. There is also an experimental CMake build for boost, supported and distributed
  92. separately. See the `Boost.CMake`_ wiki page for more information.
  93. .. _`Boost.CMake`:
  94. https://svn.boost.org/trac/boost/wiki/CMake
  95. .. include:: detail/build-from-source-head.rst
  96. For example, your session might look like this:
  97. .. parsed-literal::
  98. $ cd ~/|boost_ver|
  99. $ bjam **--build-dir=**\ /tmp/build-boost **toolset=**\ gcc stage
  100. That will build static and shared non-debug multi-threaded variants of the libraries. To build all variants, pass the additional option, “``--build-type=complete``”.
  101. .. include:: detail/build-from-source-tail.rst
  102. .. include:: detail/link-head.rst
  103. There are two main ways to link to libraries:
  104. A. You can specify the full path to each library:
  105. .. parsed-literal::
  106. $ c++ -I |root| example.cpp -o example **\\**
  107. **~/boost/stage/lib/libboost_regex-gcc34-mt-d-1_36.a**
  108. B. You can separately specify a directory to search (with ``-L``\
  109. *directory*) and a library name to search for (with ``-l``\
  110. *library*, [#lowercase-l]_ dropping the filename's leading ``lib`` and trailing
  111. suffix (``.a`` in this case):
  112. .. parsed-literal::
  113. $ c++ -I |root| example.cpp -o example **\\**
  114. **-L~/boost/stage/lib/ -lboost_regex-gcc34-mt-d-1_36**
  115. As you can see, this method is just as terse as method A for one
  116. library; it *really* pays off when you're using multiple
  117. libraries from the same directory. Note, however, that if you
  118. use this method with a library that has both static (``.a``) and
  119. dynamic (``.so``) builds, the system may choose one
  120. automatically for you unless you pass a special option such as
  121. ``-static`` on the command line.
  122. In both cases above, the bold text is what you'd add to `the
  123. command lines we explored earlier`__.
  124. __ `build a simple program using boost`_
  125. Library Naming
  126. --------------
  127. .. include:: detail/library-naming.rst
  128. .. include:: detail/test-head.rst
  129. If you linked to a shared library, you may need to prepare some
  130. platform-specific settings so that the system will be able to find
  131. and load it when your program is run. Most platforms have an
  132. environment variable to which you can add the directory containing
  133. the library. On many platforms (Linux, FreeBSD) that variable is
  134. ``LD_LIBRARY_PATH``, but on MacOS it's ``DYLD_LIBRARY_PATH``, and
  135. on Cygwin it's simply ``PATH``. In most shells other than ``csh``
  136. and ``tcsh``, you can adjust the variable as follows (again, don't
  137. type the ``$``\ —that represents the shell prompt):
  138. .. parsed-literal::
  139. **$** *VARIABLE_NAME*\ =\ *path/to/lib/directory*\ :${\ *VARIABLE_NAME*\ }
  140. **$** export *VARIABLE_NAME*
  141. On ``csh`` and ``tcsh``, it's
  142. .. parsed-literal::
  143. **$** setenv *VARIABLE_NAME* *path/to/lib/directory*\ :${\ *VARIABLE_NAME*\ }
  144. Once the necessary variable (if any) is set, you can run your
  145. program as follows:
  146. .. parsed-literal::
  147. **$** *path*\ /\ *to*\ /\ *compiled*\ /\ example < *path*\ /\ *to*\ /\ jayne.txt
  148. The program should respond with the email subject, “Will Success
  149. Spoil Rock Hunter?”
  150. .. include:: detail/conclusion.rst
  151. ------------------------------
  152. .. [#packagers] If developers of Boost packages would like to work
  153. with us to make sure these instructions can be used with their
  154. packages, we'd be glad to help. Please make your interest known
  155. to the `Boost developers' list`_.
  156. .. _Boost developers' list: http://www.boost.org/more/mailing_lists.htm#main
  157. .. [#lowercase-l] That option is a dash followed by a lowercase “L”
  158. character, which looks very much like a numeral 1 in some fonts.
  159. .. |build-type-complete| replace:: `` ``
  160. .. include:: detail/common-footnotes.rst
  161. .. include:: detail/release-variables.rst
  162. .. include:: detail/common-unix.rst
  163. .. include:: detail/links.rst
粤ICP备19079148号