基于arm-linux-gnueabihf-g++ build boost C++ library
1.前述
近期由于工作需要,要自己在板子上搭建Socket.io-client-cpp,首先需要Build boost c++ library 然后Build Socket.io-client-cpp Library,最终可Build Socket.io-client-cpp 实例。本文主要是针对搭建过程中的踩坑记录。
2.Build boost c++ library
首先,基于g++编译boost c++ library
wget https://www.boost.org/users/history/version_1_65_0.html 并解压
Run ./bootstrap.sh
#build using default gcc
Run ./b2 install
#文件(.a.so)会存在./boost_1_65_0/stage/lib中
然后using toolchain arm-linux-gnueabihf-g++ to build
需要手动修改project-config.jam文件中 using gcc ;
改为:
using gcc : arm : arm-linux-gnueabihf-g++ ;
#添加环境路径
export PATH=$PATH:/opt/gcc-sigmastar-9.1.0-2019.11-x86_64_arm-linux-gnueabihf(toolchain 的文件名)/bin
# build
./b2 -toolset=arm-linux-gnueabihf-g++ --stagedir=./stage-arm-gnueabihf-g++
报错如下:
...failed gcc.compile.c++ bin.v2/libs/python/build/gcc-arm/release/threading-multi/converter/type_id.o...
gcc.compile.c++ bin.v2/libs/python/build/gcc-arm/release/threading-multi/object/enum.o
In file included from ./boost/python/detail/wrap_python.hpp:50:0,
from ./boost/python/detail/prefix.hpp:13,
from ./boost/python/object_core.hpp:10,
from ./boost/python/object/enum_base.hpp:8,
from libs/python/src/object/enum.cpp:6:
/usr/include/python2.7/pyconfig.h:24:12: fatal error: arm-linux-gnueabihf/python2.7/pyconfig.h: No such file or directory
# include <arm-linux-gnueabihf/python2.7/pyconfig.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
...failed gcc.compile.c++ bin.v2/libs/python/build/gcc-arm/release/threading-multi/numpy/ufunc.o...
...skipped <pbin.v2/libs/python/build/gcc-arm/release/threading-multi>libboost_numpy.so.1.65.0 for lack of <pbin.v2/libs/python/build/gcc-arm/release/threading-multi>numpy/dtype.o...
...skipped <pstage-arm-gnueabihf-g++/lib>libboost_numpy.so.1.65.0 for lack of <pbin.v2/libs/python/build/gcc-arm/release/threading-multi>libboost_numpy.so.1.65.0...
...skipped <pstage-arm-gnueabihf-g++/lib>libboost_numpy.so for lack of <pstage-arm-gnueabihf-g++/lib>libboost_numpy.so.1.65.0...
...failed updating 66 targets...
...skipped 12 targets...
主要原因为/usr/include/python2.7/pyconfig.h中会引用arm-linux-gnueabihf下编译好的pyconfig.h文件,找不到arm-linux-gnueabihf/python2.7/pyconfig.h
解决方法:
Debian python-dev软件包中下载对应python2.7版本的armel.deb文件(本机版本为2.7.15rc1)并解压到include中。
#下载文件
wget http://ports.ubuntu.com/pool/main/p/python2.7/libpython2.7-dev_2.7.15~rc1-1_armhf.deb
#解压
dpkg -x libpython2.7-dev_2.7.15~rc1-1_armhf.deb libpython2.7-dev_2.7.15~rc1-1_armhf_extracted
#复制到指定位置
sudo cp -r libpython2.7-dev_2.7.15~rc1-1_armhf_extracted/usr/include/arm-linux-gnueabihf/ /usr/local/include/
修改/usr/include/python2.7/pyconfig.h中对arm-linux-gnueabihf的引用:
cd /sur/include/python2.7
sudo vim pyconfig.h
<arm-linux-gnueabihf/python2.7/pyconfig.h>
#修改为:
</usr/local/include/arm-linux-gnueabihf/python2.7/pyconfig.h>
#最终于boost文件夹运行g++ build
./b2 -toolset=arm-linux-gnueabihf-g++ --stagedir=./stage-arm-gnueabihf-g++
完美解决
...updated 78 targets...
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/home/damon/Lucien/D700/boost_1_65_0
The following directory should be added to linker library paths:
/home/damon/Lucien/D700/boost_1_65_0/stage-arm-gnueabihf-g++/lib