unix-variants.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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-libraries=`` 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. You'll also
  87. use this method if you need a nonstandard build variant (see the
  88. `Boost.Build documentation`_ for more details).
  89. .. include:: detail/build-from-source-head.rst
  90. For example, your session might look like this:
  91. .. parsed-literal::
  92. $ cd ~/|boost_ver|
  93. $ bjam **--build-dir=**\ /tmp/build-boost **toolset=**\ gcc stage
  94. 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``”.
  95. .. include:: detail/build-from-source-tail.rst
  96. .. include:: detail/link-head.rst
  97. There are two main ways to link to libraries:
  98. A. You can specify the full path to each library:
  99. .. parsed-literal::
  100. $ c++ -I |root| example.cpp -o example **\\**
  101. **~/boost/stage/lib/libboost_regex-gcc34-mt-d-1_36.a**
  102. B. You can separately specify a directory to search (with ``-L``\
  103. *directory*) and a library name to search for (with ``-l``\
  104. *library*, [#lowercase-l]_ dropping the filename's leading ``lib`` and trailing
  105. suffix (``.a`` in this case):
  106. .. parsed-literal::
  107. $ c++ -I |root| example.cpp -o example **\\**
  108. **-L~/boost/stage/lib/ -lboost_regex-gcc34-mt-d-1_36**
  109. As you can see, this method is just as terse as method A for one
  110. library; it *really* pays off when you're using multiple
  111. libraries from the same directory. Note, however, that if you
  112. use this method with a library that has both static (``.a``) and
  113. dynamic (``.so``) builds, the system may choose one
  114. automatically for you unless you pass a special option such as
  115. ``-static`` on the command line.
  116. In both cases above, the bold text is what you'd add to `the
  117. command lines we explored earlier`__.
  118. __ `build a simple program using boost`_
  119. Library Naming
  120. --------------
  121. .. include:: detail/library-naming.rst
  122. .. include:: detail/test-head.rst
  123. If you linked to a shared library, you may need to prepare some
  124. platform-specific settings so that the system will be able to find
  125. and load it when your program is run. Most platforms have an
  126. environment variable to which you can add the directory containing
  127. the library. On many platforms (Linux, FreeBSD) that variable is
  128. ``LD_LIBRARY_PATH``, but on MacOS it's ``DYLD_LIBRARY_PATH``, and
  129. on Cygwin it's simply ``PATH``. In most shells other than ``csh``
  130. and ``tcsh``, you can adjust the variable as follows (again, don't
  131. type the ``$``\ —that represents the shell prompt):
  132. .. parsed-literal::
  133. **$** *VARIABLE_NAME*\ =\ *path/to/lib/directory*\ :${\ *VARIABLE_NAME*\ }
  134. **$** export *VARIABLE_NAME*
  135. On ``csh`` and ``tcsh``, it's
  136. .. parsed-literal::
  137. **$** setenv *VARIABLE_NAME* *path/to/lib/directory*\ :${\ *VARIABLE_NAME*\ }
  138. Once the necessary variable (if any) is set, you can run your
  139. program as follows:
  140. .. parsed-literal::
  141. **$** *path*\ /\ *to*\ /\ *compiled*\ /\ example < *path*\ /\ *to*\ /\ jayne.txt
  142. The program should respond with the email subject, “Will Success
  143. Spoil Rock Hunter?”
  144. .. include:: detail/conclusion.rst
  145. ------------------------------
  146. .. [#packagers] If developers of Boost packages would like to work
  147. with us to make sure these instructions can be used with their
  148. packages, we'd be glad to help. Please make your interest known
  149. to the `Boost developers' list`_.
  150. .. _Boost developers' list: http://www.boost.org/more/mailing_lists.htm#main
  151. .. [#lowercase-l] That option is a dash followed by a lowercase “L”
  152. character, which looks very much like a numeral 1 in some fonts.
  153. .. |build-type-complete| replace:: `` ``
  154. .. include:: detail/common-footnotes.rst
  155. .. include:: detail/release-variables.rst
  156. .. include:: detail/common-unix.rst
  157. .. include:: detail/links.rst
粤ICP备19079148号