carlife交叉编译

这个东西听说很牛皮,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下,放入环境变量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值