Using Boost on ubuntu

2019-02-03 10:20发布

I've heard a lot of good comments about Boost in the past and thought I would give it a try. So I downloaded all the required packages from the package manager in Ubuntu 9.04. Now I'm having trouble finding out how to actually use the darn libraries.

Does anyone know of a good tutorial on Boost that goes all the way from Hello World to Advanced Topics, and also covers how to compile programs using g++ on ubuntu?

8条回答
男人必须洒脱
3楼-- · 2019-02-03 11:00

The library documentation is a mixed bag. Some is good, but some is more of a reference than a guide. The best guide to (some of) the Boost libraries is the book Beyond the C++ Standard Library. At the very least, the introduction gives one paragraph descriptions of many of the libraries. From there, you can decide which library is most important for your current needs, and, if it's in the book, read the chapter on it, or read the documentation on the website.

If you read German, there's a good online guide. Google translate does a good enough job that a non-speaker like me can understand it.

Also, unless you have lots of experience with C++, I'd start with the simpler libraries (e.g. smart_ptr, tuple, conversion, tokenizer, regex, date_time, test), before trying the more complicated ones (bind, variant, any), or the really advanced ones (concepts, MPL, Fusion).

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-02-03 11:03

The libraries come with documentation and many of them have tutorials as part of the documentation. Just start reading.

查看更多
我想做一个坏孩纸
5楼-- · 2019-02-03 11:06

I was just looking at that german boost guide, and found there was an english one as well (same book). It looks pretty good, have just read the introductory pages which are quite useful

查看更多
唯我独甜
6楼-- · 2019-02-03 11:08

The Boost website has some good tutorials, they are just kind of hidden.

查看更多
时光不老,我们不散
7楼-- · 2019-02-03 11:09

Agreed; the boost website has good tutorials for the most part, broken down by sub-library.

As for compiling, a good 80% of the library implementation is defined in the header files, making compiling trivial. for example, if you wanted to use shared_ptr's, you'd just add

#include <boost/shared_ptr.hpp>

and compile as you normally would. No need to add library paths to your g++ command, or specify -llibboost. As long as the boost directory is in your include path, you're all set.

From the boost documentation:

The only libraries that need to be compiled and linked are the following:The only Boost libraries that must be built separately are:

  • Boost.Filesystem
  • Boost.IOStreams
  • Boost.ProgramOptions
  • Boost.Python (see the Boost.Python build documentation before building and installing it)
  • Boost.Regex
  • Boost.Serialization
  • Boost.Signals
  • Boost.Thread
  • Boost.Wave

A few libraries have optional separately-compiled binaries:

  • Boost.DateTime has a binary component that is only needed if you're using its to_string/from_string or serialization features, or if you're targeting Visual C++ 6.x or Borland.
  • Boost.Graph also has a binary component that is only needed if you intend to parse GraphViz files.
  • Boost.Test can be used in “header-only” or “separately compiled” mode, although separate compilation is recommended for serious use.

So, if you're using one of the listed libraries, use the Getting Started guide to, well, get you started on compiling and linking to Boost.

查看更多
登录 后发表回答