【发布时间】:2012-04-06 13:56:10
【问题描述】:
我正在尝试编译加速计时器,但它抛出了我不明白的错误。这让我觉得定时器库坏了 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;
}
如果没有 timer.hpp 的#include,它会编译。使用它,它会引发以下错误:
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。
谢谢!
【问题讨论】:
-
要求一点google-fu真的太过分了吗?我们在这里有成千上万的
undefined reference问题。它们都是一样的。 -
你是直接复制粘贴那个程序,还是你输入的?至少,你似乎不见了
#include <iostream>。 -
@pmr 我用了几分钟的谷歌和stackoverflow,但我猜我的查询太具体了。我的错!
-
@Robᵩ 我复制/粘贴了。关于 iostream 的好点,但它实际上在我的系统上编译和执行得很好,我现在有点困惑。
-
@JacobBlock 机会是
lexical_cast正在拉入iostream。我不知道您是如何做到比boost undefined reference boost system gcc更具体的。您可以在选择时省略单词,但仍然可以获得完美的结果。