记boost在gcc的一个库链接问题generic_category()
2016-04-11 17:42
543 查看
报错大致如下:
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
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
相关文章推荐
- 【GoogleCodeJam2016D】【构造 找规律】Fractiles LG字符串K字符C次变为S个检测位置找金子
- golang 简易聊天
- Google Gson 使用简介
- A Bayesian Hierarchical Model for Learning Natural Scene Categories
- /data/src/dragon/bidder_mod//src/proto_adapters/dragon_wax_adapter.h:11:对‘vtable for DragonWaxAdapter’未定义的引用
- leangoo大讲堂:scrum敏捷开发实战——深圳站
- eyesight goodness
- Django REST framework教程二: 请求和响应
- django debug
- 【Leetcode】:Counting Bits问题 in Go语言
- tango with django chapter 4 Django Basics
- Django 一对多,多对多关系解析
- django-cms细节记录|篇一
- Django学习总结
- 写写Django-CMS
- groupcache源码解读
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
- HDOJ 1397 Goldbach's Conjecture(快速筛选素数法)
- django获取url参数总结
- Django基于类的视图