如何编译vSomeIP
1.下载源码
- 下载boost
wget https://boostorg.jfrog.io/native/main/release/1.74.0/source/boost_1_74_0.tar.gz
或者:
wget https://github.com/boostorg/boost/archive/refs/tags/boost-1.74.0.tar.gz
- 下载vSomeIP
wget https://github.com/COVESA/vsomeip/archive/refs/tags/3.1.20.3.tar.gz
2.编译前准备
(1)创建compressed文件夹,将boost和vSomeIP源码放入其中;
(2)在compressed同级目录创建编译脚本。
sdk_init.sh
#!/bin/bash
export PATH=~/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin:$PATH
此脚本是将交叉编译工具目录添加到PATH变量中,需要根据实际情况进行替换。
build_boost.sh
#!/bin/sh
BASE_DIR=`pwd`
#BUILD_HOST=aarch64-linux-gnu
BUILD_HOST=
BOOST=boost_1_74_0
INSTALL_DIR=${BASE_DIR}/install/${BOOST}
# 1.创建文件夹
echo "start mkdir..."
cd ${BASE_DIR}
mkdir install source -p
echo "end mkdir..."
# 2.解压源码
echo "start decompress..."
cd ${BASE_DIR}/compressed
tar -xf ${BOOST}.tar.gz -C ../source
echo "end decompress..."
# 3.配置
echo "start config..."
cd ${BASE_DIR}/source/${BOOST}
./bootstrap.sh \
--with-libraries=system,thread,log \
--prefix=${INSTALL_DIR}
if [ ${BUILD_HOST} != "" ] ; then
sed -r -i "s/using gcc ;/using gcc : : ${BUILD_HOST}-gcc ;/" project-config.jam
#sed -r -i "/^option.set libdir :/s|${INSTALL_DIR}/${BOOST}|${BASE_DIR}/ref-library|" project-config.jam
#sed -r -i "/^option.set includedir :/s|${INSTALL_DIR}/${BOOST}|${BASE_DIR}/ref-library|" project-config.jam
fi
echo "end config..."
# 4.编译
echo "--- make start ---"
cd ${BASE_DIR}/source/${BOOST}
./b2 link=shared -j4 install 2>&1 | tee ./build.log
echo "--- make end ---"
cd ${BASE_DIR}
此脚本用于编译依赖库boost。
build_someip.sh
#!/bin/sh
BASE_DIR=`pwd`
#BUILD_HOST=aarch64-linux-gnu
BUILD_HOST=
BOOST=boost_1_74_0
SOMEIP=vsomeip-3.1.20.3
INSTALL_DIR=${BASE_DIR}/install
# 1.创建文件夹
echo "start mkdir..."
cd ${BASE_DIR}
mkdir install source -p
echo "end mkdir..."
# 2.解压源码
echo "start decompress..."
cd ${BASE_DIR}/compressed
tar -xf ${SOMEIP}.tar.gz -C ../source
echo "end decompress..."
# 3.配置
echo "start config..."
cd ${BASE_DIR}/source/${SOMEIP}
mkdir build -p
cd build
if [ ${BUILD_HOST} != "" ] ; then
cmake -DCMAKE_C_COMPILER=${BUILD_HOST}-gcc \
-DCMAKE_CXX_COMPILER=${BUILD_HOST}-g++ \
-DBOOST_ROOT=${INSTALL_DIR}/${BOOST} \
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}/${SOMEIP} \
-DENABLE_SIGNAL_HANDLING=1 \
..
else
cmake -DBOOST_ROOT=${INSTALL_DIR}/${BOOST} \
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}/${SOMEIP} \
-DENABLE_SIGNAL_HANDLING=1 \
..
fi
echo "end config..."
# 4.编译
echo "--- make start ---"
cd ${BASE_DIR}/source/${SOMEIP}/build
make clean
make -j4 2>&1 | tee ./build.log
make install
echo "--- make end ---"
cd ${BASE_DIR}
此脚本用于编译依赖库vSomeIP。
至此,工作目录结构如下:
3.编译vSomeIP
3.1编译PC版本
(1)将build_boost.sh和build_someip.sh脚本中BUILD_HOST变量设为空值;
(2)运行build_boost.sh脚本;
(3)运行build_someip.sh脚本。
3.2交叉编译
(1)将build_boost.sh和build_someip.sh脚本中BUILD_HOST变量设为交叉编译器对应的值(如:BUILD_HOST=aarch64-linux-gnu);
(2)用source命令执行sdk_init.sh脚本;
source sdk_init.sh
(3)运行build_boost.sh脚本;
(4)运行build_someip.sh脚本。