【问题标题】:Boost timer doesn't compile升压计时器无法编译
【发布时间】: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 &lt;iostream&gt;
  • @pmr 我用了几分钟的谷歌和stackoverflow,但我猜我的查询太具体了。我的错!
  • @Robᵩ 我复制/粘贴了。关于 iostream 的好点,但它实际上在我的系统上编译和执行得很好,我现在有点困惑。
  • @JacobBlock 机会是lexical_cast 正在拉入iostream。我不知道您是如何做到比boost undefined reference boost system gcc 更具体的。您可以在选择时省略单词,但仍然可以获得完美的结果。

标签: c++ boost timer


【解决方案1】:

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

【讨论】:

  • 我想我仍然对包含和库链接感到困惑。现在可以使用了,谢谢!
【解决方案2】:

这些错误与 Boost Timer 库无关,不,库没有损坏。正如introductory material 指定的那样,

Boost.Timer 是作为单独编译的库实现的,因此您必须将二进制文件安装在链接器可以找到的位置。

...并在调用编译器时将相应的库添加为命令行参数(使用-lLIBNAME),如果使用IDE、CMake 或Makefile,则将它们添加到项目配置中。在发表贬义之前,请确保您首先了解Boost Getting Started guide中讨论的细节。

【讨论】:

    【解决方案3】:

    您还必须包含基本增强系统标头。检查您需要的默认标题的示例之一。

    【讨论】:

    • 这不是关于标题,而是链接库
    • 哎呀,没看到这是链接器错误。上次我尝试使用 SO 移动应用回答问题 =\
    【解决方案4】:

    您忘记链接 boost_system。 像这样:

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

    会好的

    【讨论】:

      猜你喜欢
      • 2016-09-10
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多