BOOST库 将源码作交叉编译 书籍下载

好记性不如烂笔头,BOOST库的移植,我也记录一下。

 

1. BOOST库 版本1.66.0 下载地址, 附书籍C++ BOOST库开发指南:

 https://download.csdn.net/download/qq_37372700/12960498

 

2.交叉编译:

当前环境:

编译脚本:

my_compile_boost.sh:

#xcompile_boost.sh

mfile=project-config.jam

if [ -e ${mfile} ];then
    rm ${mfile}
    echo "rm ${mfile}"
fi

#--with-libraries指定编译哪些boost库,all的话就是全部编译,
#                   只想编译部分库的话就把库的名称写上,之间用 , 号分隔即可

#--with-libraries=system,filesystem,regex 

./bootstrap.sh 
--with-libraries=all 
--prefix=/home/lmw/open_lib/boost/boost_stuphere

if [ -e ${mfile} ];then
    mhost="mips-linux-gnu-g++ -fPIC"
    sed -i "/using gcc/c using gcc : mips : ${mhost} ; " ${mfile}
fi

echo "After 5s start compile"
sleep 5s
./b2

echo "Afer 5s start install"
sleep 5s
./b2 install

接着将所需的库文件挪到嵌入式系统内(根据自己调库的需要进行选择,同时考虑嵌入式的磁盘大小情况),

或者也可以直接把库文件放到ubuntu主机内的根文件系统内,重新制作下镜像,然后烧录系统到嵌入式设备上。

然后创建几个符号链接,如下图红色箭头所示。

3.测试代码

当前环境:

my_boost_test.cpp:

// test1 -- ( boost::this_thread::sleep() ) -- Success

#include <boost/thread/thread.hpp>
#include <iostream> 

void wait(int seconds) 
{ 
    boost::this_thread::sleep(boost::posix_time::seconds(seconds)); 
} 

void thread() 
{ 
    for (int i = 0; i < 5; ++i) 
    { 
        wait(1); 
        std::cout << i << std::endl; 
    } 
} 

int main() 
{ 
    boost::thread t(thread); 

    t.join(); 
}

makefile:

.PHONY: DOIT

DOIT:
    mips-linux-gnu-g++ -I.  my_boost_test.cpp -L./lib  -lboost_thread -lboost_system -o boost_app

 

 

 

 

 

.

 

/************* 社会的有色眼光是:博士生、研究生、本科生、车间工人; 重点大学高材生、普通院校、二流院校、野鸡大学; 年薪百万、五十万、五万; 这些都只是帽子,可以失败千百次,但我和社会都觉得,人只要成功一次,就能换一顶帽子,只是社会看不见你之前的失败的帽子。 当然,换帽子决不是最终目的,走好自己的路就行。 杭州.大话西游 *******/
原文地址:https://www.cnblogs.com/happybirthdaytoyou/p/13837384.html