在 ubuntu 上使用 Boost

发布于 2024-07-19 03:14:15 字数 164 浏览 7 评论 0原文

我过去听过很多关于 Boost 的好评,我想尝试一下。 所以我从Ubuntu 9.04的包管理器下载了所有需要的包。 现在我很难找到如何实际使用该死的库。

有谁知道关于 Boost 的好教程,从 Hello World 到高级主题,还涵盖如何在 ubuntu 上使用 g++ 编译程序?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

回忆凄美了谁 2024-07-26 03:14:15

同意; boost 网站 大部分内容都有很好的教程,按子库细分。

至于编译,80% 的库实现都定义在头文件中,使得编译变得微不足道。 例如,如果您想使用shared_ptr,您只需

#include <boost/shared_ptr.hpp>

像平常一样添加和编译即可。 无需将库路径添加到 g++ 命令,或指定 -llibboost。 只要 boost 目录位于您的包含路径中,就万事大吉了。

来自提升文档:

唯一需要编译和链接的库如下:唯一必须单独构建的 Boost 库是:

  • Boost.文件系统
  • Boost.IOStreams
  • Boost.ProgramOptions
  • Boost.Python(在构建和安装之前请参阅 Boost.Python 构建文档)
  • Boost.Regex
  • Boost.序列化
  • Boost.Signals
  • Boost.Thread
  • Boost.Wave

一些库有可选的单独编译的二进制文件:

  • Boost.DateTime 有一个二进制组件,仅当您使用其 to_string/from_string 或序列化功能,或者您的目标平台为 Visual C++ 6.x 或 Borland 时才需要该组件。
  • Boost.Graph 还有一个二进制组件,仅在您打算解析 GraphViz 文件时才需要。
  • Boost.Test 可以在“仅标头”或“单独编译”模式下使用,但建议认真使用时单独编译。

因此,如果您使用的是列出的库之一,请使用 入门指南,让您开始编译和链接到 Boost。

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.

东北女汉子 2024-07-26 03:14:15

Boost 网站有一些很好的教程,它们只是隐藏的.

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

岛歌少女 2024-07-26 03:14:15

库文档是一个混合包。 有些是好的,但有些更多的是参考而不是指南。 (某些)Boost 库的最佳指南是Beyond the C++ Standard Library< /a>. 至少,引言给出了许多库的一段描述。 从那里,您可以决定哪个库对您当前的需求最重要,如果它在书中,请阅读它的章节,或阅读网站上的文档。

如果您阅读德语,这里有一个很好的在线指南。 谷歌翻译做得足够好,像我这样不会说话的人也能理解它。

另外,除非你有丰富的 C++ 经验,否则我会从更简单的库(例如 smart_ptr、tuple、conversion、tokenizer、regex、date_time、test)开始,然后再尝试更复杂的库(bind、variant、any),或者真正先进的(概念、MPL、Fusion)。

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).

爱,才寂寞 2024-07-26 03:14:15

使用基于 Ubuntu 的 Easypeasy 1.1(用于上网本),我相信我能够使用 Synaptic Package Manager 来安装 libboost-dev。 然后只需添加:

#include "boost/foreach.hpp"

我就能够替换现有应用程序中的现有行(该应用程序有一个与 boost 无关的 Ask 类):

for (std::vector<Ask*>::iterator ii=ui.begin(); ii!=ui.end(); ++ii)
    std::cout << (*ii)->prompt() << (*ii)->answer() << std::endl;

with:

BOOST_FOREACH (Ask* ii, ui)
     std::cout << ii->prompt() << ii->answer() << std::endl;

据我了解,这是仅标头功能。 我还没有使用任何需要更改链接时间的东西。

Using Easypeasy 1.1 (for netbooks) which is based upon Ubuntu I was able to use Synaptic Package Manager to install, I believe, libboost-dev. Then simply by adding:

#include "boost/foreach.hpp"

I was able to replace the existing lines in an existing application (which has an Ask class which has nothing to do with boost):

for (std::vector<Ask*>::iterator ii=ui.begin(); ii!=ui.end(); ++ii)
    std::cout << (*ii)->prompt() << (*ii)->answer() << std::endl;

with:

BOOST_FOREACH (Ask* ii, ui)
     std::cout << ii->prompt() << ii->answer() << std::endl;

As I understand it this is a header only feature. I have not used anything requiring link time changes yet.

攒一口袋星星 2024-07-26 03:14:15

我只是在看德语 boost 指南,发现还有一个 英语 指南(同一本书)。 看起来不错,刚刚看了介绍页,非常有用

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

残月升风 2024-07-26 03:14:15

这些库附带文档,其中许多库都包含教程作为文档的一部分。 开始阅读吧。

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

影子是时光的心 2024-07-26 03:14:15

Boost 不是一种编程语言,也不是一个应用程序框架 - 因为它只是一个库的集合,所以不存在 Boost“Hello World”程序之类的东西。 Boost 中的大多数库或多或少都可以独立使用,它们的大小各不相同,从一个函数到可以独立的大型库。

了解 Boost 的最佳方法就是在编写新代码时尝试使用它。 尽可能使用 smart_ptr; 下次您想要进行编译时工作时,请使用 MPL。 Boost 有很多种类,但您可能应该开始查看实用程序部分; 这些是最轻量且最常用的库。

Boost is not a programming language nor an application framework - because it's just a collection of libraries, there is no such thing as a Boost 'Hello World' program. Most libraries in Boost can be used more or less independently, and they vary in size from one function to massive libraries that could stand alone.

The best way to get to know Boost is simply to try and work it in as you write new code. Use smart_ptr whenever you can; use the MPL next time you want to do compile-time work. There's a lot of variety in Boost, but you should probably start looking at the Utility section; those are the lightest-weight and most commonly-used libraries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文