这个东西听说很牛皮,15年就开始研发了,但我今天才接触到,感受到大厂的预见跟资源,因为要移植到arm板上,所以要进行交叉编译,也是遇到了一些坑,记录一下以免以后忘记
1.下载源码
https://github.com/ApolloAuto/apollo-DuerOS/tree/master/CarLife-Vehicle-Lib
CarLife-Vehicle-Lib这个目录下是linux版的车机端源码
2.进入目录,解压protobuf-2.5.0.tar.gz
3.cd protobuf-2.5.0/
4.直接编译
./configure(默认安装路径/usr/local/include lib)
make
make check
sudo make install
5.交叉编译
./configure --build=x86_64-unknown-linux-gnu --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ --with-protoc=protoc --prefix=/usr/protobuf --disable-shared
make
make check(有错,不用理)
sudo make install
–build=x86_64-unknown-linux-gnu 编译的机器
–host=arm-linux-gnueabihf 运行机器
CC=arm-linux-gnueabihf-gcc c编译工具链
CXX=arm-linux-gnueabihf-g++ c++编译工具链
–prefix=/usr/protobuf 安装路径
如果有报错找不到protoc的话,需要安装
sudo apt-get install protobuf-compiler
6.编译carlife源码
6.1 在makefile中加入工具链
#Author:
# Liu CaiQuan
#Date:
# 7th Semptember 2015
#CarLife Protocol version:
# V0.15
#
#rule for Linux
#
# Copyright (C) Under BaiDu, Inc.
#TOPDIR:=~/EddyWorkSpace/CarLifeLibSourceCode/trunk
TOPDIR:=$(shell pwd)
export TOPDIR
#CROSS_COMPILE=
CROSS_COMPILE ?=arm-linux-gnueabihf-
LD=$(CROSS_COMPILE)ld
CC=$(CROSS_COMPILE)g++
CP=cp
export LD CC
#COM_FLAGS = -Wall -O2 -fPIC -mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=hard -mthumb-interwork -marm
#CFLAGS = $(COM_FLAGS) -std=c++14
#CFLAGS = -g
CFLAGS:=-g -Wall -O2 -fPIC -mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=hard -mthumb-interwork -marm -std=c++11
CFLAGS+=-I protobuf/cc/include
CFLAGS+=-I $(TOPDIR)/include
CFLAGS+=-I $(TOPDIR)/protobuf/cc/include
#CFLAGS+=-I /usr/local/include
#CFLAGS+=-I /usr/local/include/google/protobuf
#CFLAGS+=-I /usr/local/include/google/protobuf/io
#CFLAGS+=-I /usr/local/include/google/protobuf/stubs
CFLAGS+=-I /usr/protobuf/include
CFLAGS+=-I /usr/protobuf/include/google/protobuf
CFLAGS+=-I /usr/protobuf/include/google/protobuf/io
CFLAGS+=-I /usr/protobuf/include/google/protobuf/stubs
#CFLAGS+=-I /usr/include //跟本地的头文件有冲突,需要去掉
CFLAGS+=-I /usr/include/libxml2
#LFLAGS:=-fPIC -shared
#LFLAGS+=-L/usr/local/lib -lprotobuf
LFLAGS+=-L/usr/protobuf/lib -lprotobuf
#LFLAGS+=-L/usr/protobuf/lib -L/usr/protobuf/lib/libprotobuf.a
export CFLAGS LFLAGS
OBJDIR=obj
#obj-y+=CarLifeLibTest.o
obj-y+=core/
obj-y+=libwrapper/
obj-y+=modules/
obj-y+=protobuf/
obj-y+=utility/
TARGET-LIB=libcarlifevehicle.so
TARGET-APP=libtest
all: carlifelib libtest
carlifelib:
make -C ./ -f $(TOPDIR)/Makefile.build
$(CC) -shared -o $(TARGET-LIB) built-in.o
$(CP) $(TARGET-LIB) $(OBJDIR)
libtest:CarLifeLibTest.cpp
$(CC) -o $(TARGET-APP) $< -Iinclude -L./ -lcarlifevehicle -lpthread $(LFLAGS)
$(CP) $(TARGET-APP) $(OBJDIR)
protoBuf:
rm -f ./protobuf/pbGen/*
protoc --proto_path=./protobuf/proto/ --cpp_out=./protobuf/pbGen ./protobuf/proto/*.proto
rm -f ./protobuf/cc/src/*.cc
rm -f ./protobuf/cc/include/*.h
mv ./protobuf/pbGen/*.cc ./protobuf/cc/src/
mv ./protobuf/pbGen/*.h ./protobuf/cc/include/
clean:
rm -f $(shell find -name "*.o")
rm -f $(TARGET-LIB)
rm -f $(TARGET-APP)
rm -f $(OBJDIR)/*
distclean:
rm -f $(shell find -name "*.o")
rm -f $(shell find -name "*.d")
rm -f $(TARGET-LIB)
rm -f $(TARGET-APP)
rm -f $(OBJDIR)/*
7.将libtest ,obj,libcarlifevehicle.so复制到板子上
8.搭建arm运行环境
8.1将protobuf库移植到arm板上,将/usr/protobuf/lib/* 拷贝到存有libtest文件的路径下,也可以将其拷贝到/usr/lib下,放入环境变量