在 ubuntu 上使用 Boost
我过去听过很多关于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
同意; boost 网站 大部分内容都有很好的教程,按子库细分。
至于编译,80% 的库实现都定义在头文件中,使得编译变得微不足道。 例如,如果您想使用shared_ptr,您只需
像平常一样添加和编译即可。 无需将库路径添加到 g++ 命令,或指定 -llibboost。 只要 boost 目录位于您的包含路径中,就万事大吉了。
来自提升文档:
因此,如果您使用的是列出的库之一,请使用 入门指南,让您开始编译和链接到 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
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:
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.
Boost 网站有一些很好的教程,它们只是隐藏的.
The Boost website has some good tutorials, they are just kind of hidden.
库文档是一个混合包。 有些是好的,但有些更多的是参考而不是指南。 (某些)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).
使用基于 Ubuntu 的 Easypeasy 1.1(用于上网本),我相信我能够使用 Synaptic Package Manager 来安装 libboost-dev。 然后只需添加:
我就能够替换现有应用程序中的现有行(该应用程序有一个与 boost 无关的 Ask 类):
with:
据我了解,这是仅标头功能。 我还没有使用任何需要更改链接时间的东西。
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:
I was able to replace the existing lines in an existing application (which has an Ask class which has nothing to do with boost):
with:
As I understand it this is a header only feature. I have not used anything requiring link time changes yet.
我只是在看德语 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
到目前为止我读过的最好的教程是这两本书:
The best tutorial I've read so far are those two books:
这些库附带文档,其中许多库都包含教程作为文档的一部分。 开始阅读吧。
The libraries come with documentation and many of them have tutorials as part of the documentation. Just start reading.
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.