如何安装和使用Boost?

时间:2013-03-08 18:32:08

标签: c++ boost

我是C ++的新手,我第一次尝试安装和使用Boost库。我正在尝试编译和高分辨率计时的例子:

#include <boost/timer/timer.hpp>
#include <cmath>

int main()
{
   boost::timer::auto_cpu_timer t;

   for (long i = 0; i < 100000000; ++i)
      std::sqrt(123.456L); // burn some time

   return 0;
}

然而,当我尝试编译这个时,我似乎没有接受升级库的洗浴:

$ g++ -Wall -I ~/boost_1_53_0 boost_cpu_timer.cc
Undefined symbols for architecture x86_64:
    "boost::timer::auto_cpu_timer::auto_cpu_timer(short)", referenced from:
        _main in ccQSlF30.o
    "boost::timer::auto_cpu_timer::~auto_cpu_timer()", referenced from:
        _main in ccQSlF30.o
    "boost::system::generic_category()", referenced from:
        __static_initialization_and_destruction_0(int, int)in ccQSlF30.o
    "boost::system::system_category()", referenced from:
       __static_initialization_and_destruction_0(int, int)in ccQSlF30.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

我使用建议的命令安装了boost:

$ tar xzfv boost_1_53_0.tar.bz2
$ cd boost_1_53_0
$ ./bootstrap.sh --prefix=/usr/local
$ sudo ./b2 --prefix=/usr/local install

在/ usr / local中安装了一些动态库,即     $ ls / usr / local / lib /     ...     libboost_timer.a
    libboost_date_time.a
    libboost_timer.dylib     ...

但是我仍然没有建立如何使用boost标头编译C ++代码的连接,例如

#include <boost/timer/timer.hpp>

非常感谢任何帮助。

0 个答案:

没有答案