boost庫安裝與測試

在網上找了半天都不好用,這個真好用!!!

開始編譯,全部編譯耗時太多,所以我僅選擇我需要的庫:

先用下面的命令查看有多少庫可以編譯:
./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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章