记boost在gcc的一个库链接问题generic_category()

7 篇文章 0 订阅

报错大致如下:

main.cpp:(.text+0x49): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x53): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x5d): undefined reference to `boost::system::system_category()'

当时搞了很久,各种库各种一通链接,始终没解决问题

解决方案:

"boost/filesystem.hpp" 这个文件依赖于boost_system,编译的时候,需要 -lboost_system选项,但是你的编译选项里头已经指定该选项,为什么还会出现链接错误呢。我也纳闷了半天,后来发现,原来是-l选项的顺序问题。在g++的man帮助信息里面,我发现了下面的话:

引用 It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.
读完这段话,应该就明白出错原因了。所以,解决方案就是用下面的命令来编译:
引用 g++ main.cpp -lboost_system -lboost_filesystem

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值