我是 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;
}
但是,当我尝试编译它时,我似乎并没有为 boost 库洗澡:
$ 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>
任何帮助深表感谢。