boost库安装与测试

9 篇文章 0 订阅

在网上找了半天都不好用,这个真好用!!!

开始编译,全部编译耗时太多,所以我仅选择我需要的库:

先用下面的命令查看有多少库可以编译:
./bootstrap.sh --show-libraries
Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86_64/b2
The following Boost libraries have portions that require a separate build
and installation step. Any library not listed here can be used by including
the headers only.
The Boost libraries requiring separate building and installation are:
    - atomic
    - chrono
    - context
    - coroutine
    - date_time
    - exception
    - filesystem
    - graph
    - graph_parallel
    - iostreams
    - locale
    - log
    - math
    - mpi
    - program_options
    - python
    - random
    - regex
    - serialization
    - signals
    - system
    - test
    - thread
    - timer
    - wave
然后就编译我要的库:
./bootstrap.sh --with-libraries=system,filesystem,log,thread
Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86_64/b2
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...
Bootstrapping is done. To build, run:
    ./b2
    
To adjust configuration, edit 'project-config.jam'.
Further information:
  - Command line help:
    ./b2 --help
    
  - Getting started guide: 
    http://www.boost.org/more/getting_started/unix-variants.html
    
  - Boost.Build documentation:
    http://www.boost.org/boost-build2/doc/html/index.html
然后运行下面的命令完成编译。
./b2
耐心等待。不过因为不是编译所有库。时间会少很多。以后需要再来编译。很快看到结果:
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/usr/src/boost_1_54_0
The following directory should be added to linker library paths:
/usr/src/boost_1_54_0/stage/lib
再运行./b2 install 命令,默认安装在
/usr/local/lib目录下
头文件在
/usr/local/include/boost目录下


修改/etc/profie文件 末尾添加
export BOOST_INCLUDE=/usr/local/include/boost-1_54
export BOOST_LIB=/usr/local/lib


测试程序
#include <boost/lexical_cast.hpp>  
#include <iostream>  
int main()  
{  
using boost::lexical_cast;  
int a = lexical_cast<int>("123");  
double b = lexical_cast<double>("123.12");  
std::cout<<a<<std::endl;  
std::cout<<b<<std::endl;  
return 0;  
}  


make程序(这个是自己写的,其他都是摘自http://blog.csdn.net/alec1987/article/details/10001569):
.SUFFIXES:.h .c .cpp .o


CC=$(CXX) $(CXX_FLAG)


RM = rm
SRCS = boost.cpp
PROGRAM = boosttest
OBJS=$(SRCS:.cpp=.o)


INC_PATH =  -I$(BOOST_INCLUDE)
LIB_PATH =  -L$(BOOST_LIB)
LIBS =


$(PROGRAM):$(OBJS)
$(CC) $? $(LIB_PATH) $(LIBS) -o $@


$(OBJS):$(SRCS)
$(CC) $(CPPFLAGS) -c $(SRCS)  $(INC_PATH)

.PHONY:clean
clean:
$(RM) $(PROGRAM) $(OBJS)


输出:
123
123.12
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值