【错误】undefined reference to `boost::....的解决
很多新手引用Boost库编程,在ubuntu下编译时候有时候会出现如下错误:
test04.cpp:(.text+0x2c): undefined reference to `boost::program_options::options_description::m_default_line_length'
test04.cpp:(.text+0x37): undefined reference to `boost::program_options::options_description::m_default_line_length'
test04.cpp:(.text+0x7c): undefined reference to `boost::program_options::options_description::options_description(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)'
这个问题的出现是因为使用g++编译C++项目文件时,没有链接Link上对应所需的库。解决办法有两种:
(1)在编译文件时加上配置选项
比如,一般情况下test.cpp编译时的语句为:
g++ -std=c++11 -o test.elf test.cpp
在使用了Boost库出现上述问题时,在后面加上“-lboost_具体库名”可将编译语句改为:
g++ -std=c++11 -o test.elf test.cpp -lboost_program_options
如果报错为“undefined reference to `boost::system::....'”就可以加上-lboost_system
注释:当使用C++11标准库时需要在编译配置中加上“-std=c++11”,一半情况下使用新版的Boost都会掺杂C++11的内容,所以这个配置项最好加上。
(2)在Makefile中修改配置
如:打开Makefile找到规则
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
修改为:
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) -lboost_system -lboost_thread
注意Makefile的格式/tab与空格是有定义区别的,而如果用QTCreator打开Makefile,保存时会以数个空格替换掉/tab,这将导致后续make不能执行,所以需要用比如Vim这样的编辑器打开修改。
(3)关于#include <>
使用Boost,添加几个:
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/options_description.hpp>
#include ...........................
和使用1个:
#include <boost/program_options.hpp>
功能是一样的,如果能够精确知道使用的类属于哪个文件,最好使用第一种#include方式,如果不知道,可以使用第二种。
【错误】undefined reference to `boost::....的解决的更多相关文章
- [转载]解决linux 下多线程错误 undefined reference to `sem_init'
转自:https://blog.csdn.net/yzycqu/article/details/7396498?utm_source=copy 解决linux 下多线程错误 undefined ref ...
- 解决错误---undefined reference to `pthread_create‘
今天试着敲了一下APUE的小例子,遇到了个错误 ----- undefined reference to `pthread_create.(为自己这么晚接触多线程惭愧). 上网上查了一下,借人经验. ...
- 错误 undefined reference to __cxa_guard_acquire/release
用gcc编译 c++ 程序时,出现错误 undefined reference to __cxa_guard_acquire linker error, 但是用icc可以正常编译, 问题出在stati ...
- 「caffe编译bug」 undefined reference to `boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::__cxx11
CXX/LD -o .build_release/tools/test_net.binCXX/LD -o .build_release/tools/convert_annoset.binCXX/LD ...
- boost中g++ 链接undefined reference to `boost::system::generic_category()问题
编译错误如下: g++ -std=c++11 tcp_session.cpp tcp_server.cpp test.cpp -o test -pthread/tmp/ccv4rZkD.o: In ...
- 问题:eclipse中线程编程编译报错,undefined reference to 'pthread_create'的解决方法(已解决)
问题描述: 在Ubuntu系统中,使用eclipse CDT集成开发环境编写pthread程序,编译时,pthread_create不通过,报错信息是: undefined reference to ...
- cocos2dx添加新的类后出现错误undefined reference to的解决办法
使用cocos compile -p android编译cocos2dx项目的时候出现如下错误(新建了TestScene.h,TestScene.cpp): jni/../../Classes/App ...
- 编译3.10内核 出现错误 “undefined reference to...." 解决方法
向内核中加入C文件后.假设想编译进内核须要改动当前文件夹下的Kconfig文件和Makefile文件. 如:加入一个test.c文件到driver文件夹下,则须要改动Kconfig文件: config ...
- Android编译错误——undefined reference to
[错误描述] 未定义引用 提示如下:bootable/recovery/minzip/Zip.c:1122: error: undefined reference to 'selabel_lookup ...
随机推荐
- 解决oracle用户锁定
故障现象: SQL> connect scott/scottERROR:ORA-01017: invalid username/password; logon deniedSQL> ...
- 运用三角不等式加速Kmeans聚类算法
运用三角不等式加速Kmeans聚类算法 引言:最近在刷<数据挖掘导论>,第九章, 9.5.1小节有提到,可以用三角不等式,减少不必要的距离计算,从而达到加速聚类算法的目的.这在超大数据量的 ...
- 如何为mysql添加、启动服务
1.点击"开始",输入cmd,以管理员身份运行: 2.进入mysql的bin目录,执行 mysqld --install,然后执行 net start mysql :
- 【源码学习】之requirejs
对于现在的前端生态来说,requirejs是有点过时了,webpack帮我们包干了一切.但是对于学习源码这件事情来说,永远是不过时的! 最近稍微闲下来了一点,就着以前做过的项目,我也来看看requir ...
- Welcome to my Blog
Only English? Oh my god!!! why open live write can't write by Chinese?
- Charles安装破解及使用
摘要 在发开过程中,追踪请求和监控请求与返回数据是我们经常会需要的一个需求,在Mac端,Charles是一款非常易用的抓包工具. Mac端的优秀抓包工具--Charles使用 一.简介 Charles ...
- springboot(四):thymeleaf使用详解
在上篇文章springboot(二):web综合开发中简单介绍了一下thymeleaf,这篇文章将更加全面详细的介绍thymeleaf的使用.thymeleaf 是新一代的模板引擎,在spring4. ...
- 什么是mybatis 为什么要使用my batis
1.定义MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.2.使用原因MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以使用 ...
- gitignore.io-程序猿值得拥有的智能生成gitignore文件的秘密武器
gitignore.io Create useful .gitignore files for your project by selecting from 360 Operating System, ...
- PHP 底层的运行机制与原理 --转
发现一片总结的还不错的文章,记录一下 PHP说简单,但是要精通也不是一件简单的事.我们除了会使用之外,还得知道它底层的工作原理. PHP是一种适用于web开发的动态语言.具体点说,就是一个用C语言实现 ...