link-head.rst 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. Link Your Program to a Boost Library
  5. ====================================
  6. To demonstrate linking with a Boost binary library, we'll use the
  7. following simple program that extracts the subject lines from
  8. emails. It uses the Boost.Regex_ library, which has a
  9. separately-compiled binary component. ::
  10. #include <boost/regex.hpp>
  11. #include <iostream>
  12. #include <string>
  13. int main()
  14. {
  15. std::string line;
  16. boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
  17. while (std::cin)
  18. {
  19. std::getline(std::cin, line);
  20. boost::smatch matches;
  21. if (boost::regex_match(line, matches, pat))
  22. std::cout << matches[2] << std::endl;
  23. }
  24. }
  25. There are two main challenges associated with linking:
  26. 1. Tool configuration, e.g. choosing command-line options or IDE
  27. build settings.
  28. 2. Identifying the library binary, among all the build variants,
  29. whose compile configuration is compatible with the rest of your
  30. project.
粤ICP备19079148号