【错误】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 ...
随机推荐
- 蓝桥杯-打印大X-java
/* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2016, 广州科技贸易职业学院信息工程系学生 * All rights reserved. * 文件名称: ...
- ASP.NET Core开发之HttpContext
ASP.NET Core中的HttpContext开发,在ASP.NET开发中我们总是会经常用到HttpContext. 那么在ASP.NET Core中要如何使用HttpContext呢,下面就来具 ...
- FineReport使用总结
一.常用函数和变量 1. 日期 1.1 now() 当前时间 1.2 today() 今天 1.3 格式化显示,插入公式 =format($$$,"yyyy年MM月dd日 HH:mm&quo ...
- iOS APP开发设置启动图片 Launch Image
一.添加启动图片 点击Assets.xcassets进入图片管理,右击,弹出"New Launch Image"或点下面的+号创建Launch Image: 这里首先说明一下尺寸: ...
- 最大流算法之ISAP
序: 在之前的博文中,我解释了关于最大流的EK与Dinic算法,以及它们的STL/非STL的实现(其实没什么区别).本次讲解的是ISAP算法.'I',指 inproved,也就是说ISAP其实是SAP ...
- OC中常见的结构体,以及NSNumber、NSValue、NSDate的使用
常见的结构体 NSPoint和CGPoint NSSize和CGSize NSRect 和 CGRect NSPoint和CGPoint的使用 NSPoint和CGPoint是同义的 typedef ...
- spoj 694. Distinct Substrings 后缀数组求不同子串的个数
题目链接:http://www.spoj.com/problems/DISUBSTR/ 思路: 每个子串一定是某个后缀的前缀,那么原问题等价于求所有后缀之间的不相同的前缀的个数.如果所有的后缀按照su ...
- 精准准确的统一社会信用代码正则(js)
参照标准: <GB_32100-2015_法人和其他组织统一社会信用代码编码规则.> 按照编码规则: 统一代码为18位,统一代码由十八位的数字或大写英文字母(不适用I.O.Z.S.V)组成 ...
- EF Core 2.0 新特性
前言 目前 EF Core 的最新版本为 2.0.0-priview1-final,所以本篇文章主要是针对此版本的一些说明. 注意:如果你要在Visual Studio 中使用 .NET Core 2 ...
- Python 基本数据类型_常用功能整理
一.字符串 字符串 s ="axle" #去两端空格 s.split() #以什么开头 s.startswith("a") #查找子序列,"12&qu ...