2012-04-06 67 views
-3

我想编译升压计时器,它是抛出错误,我不明白。它让我觉得定时器库在atm处被破坏:升压计时器不编译

#include <string> 
#include <boost/lexical_cast.hpp> 
#include <boost/timer/timer.hpp> 

int main(int argc, char **argv) { 
// auto_cpu_timer t; 
    std::cout << boost::lexical_cast<std::string>(2.0) << std::endl; 

    return 0; 
} 

没有#include for timer.hpp它编译。有了它,它会抛出以下错误:

Invoking: GCC C++ Linker 
g++ -Lsrc -o "timetest" ./src/main.o 
./src/main.o: In function `__static_initialization_and_destruction_0': 
/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()' 
/usr/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()' 
/usr/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()' 
collect2: ld returned 1 exit status 
make: *** [timetest] Error 1 

这是否意味着计时器库被摧毁atm?我正在使用Boost 1.49.0。

谢谢!

+1

难道真的要求太多了一点谷歌福?我们在这里有数千个“未定义的参考”问题。他们都是一样的。 – pmr 2012-04-06 14:14:04

+0

您是否直接复制粘贴该程序,或者是否输入了该程序?你好像至少错过了'#include '。 – 2012-04-06 14:14:49

+0

@pmr我做了几分钟的谷歌和stackoverflow,但我的查询过于具体,我猜。我的错! – 2012-04-06 14:19:36

回答

5

假设您使用gcc,请尝试将-lboost_system添加到您的编译器命令行以便与该库链接。

+0

我想我仍然混淆了包含和库链接。现在就工作,谢谢! – 2012-04-06 14:11:59

+0

也-lboost_timer – xinthose 2015-07-25 23:45:21

0

你也必须包含基本的boost系统头文件。选中您需要的默认标题的示例之一。

+0

这不是关于标题,而是链接库 – 2012-04-06 14:01:57

+0

woops,没有看到它是一个链接器错误。上次我尝试使用SO移动应用程序来回答问题= \ – 2012-04-06 14:12:46

2

这些错误与Boost Timer库无关,并且不存在,库不会损坏。由于这introductory material指定,

Boost.Timer是作为一个单独编译的库,所以你必须在你的链接器中找到一个位置安装二进制文件。

...并添加按照库作为命令行参数调用编译器时(使用-lLIBNAME),或者如果使用IDE,CMake的或Makefile文件将它们添加到您的项目配置。确保您在做便宜的评论之前首先了解Boost Getting Started guide中讨论的细节。

0

你忘记链接boost_system。 像这样:

g++ -Lsrc -o "timetest" ./src/main.o -lboost_system 

将罚款