好記性不如爛筆頭,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
.